暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

EKS企业实战---已存在的VPC中ip不够了,在EKS中需要做什么

耶喝运维 2021-03-30
1176

遇到的问题

在企业中,一般都会遇到这种情况,如果使用了专线打通了云厂商的网络,那么vpc会被规划的很小,这样如果创建EKS就会出现ip 不够使用的情况,我们就会给一个vpc附加多个CIDR的方式,这种架构可以让pod 与node不在一个CIDR中,让pod使用的ip池足够大。

Muti CIDR网络架构图


使用eksctl 创建EKS集群

eksctl 部署与使用方式请查看我之前的文章 在已存在的vpc中使用eksctl 创建eks,创建 cluster.yaml

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig


metadata:
  name: eks-test-01
  region: us-west-2


vpc:
  id: "vpc-xxxxxxxxx"
  subnets:
    private:
      us-west-2a:
          id: "subnet-xxxxxxxx"
      us-west-2b:
          id: "subnet-xxxxxxxx"
    public:
      us-west-2a:
          id: "subnet-xxxxxxxx"
      us-west-2b:
          id: "subnet-xxxxxxxx"

复制

使用命令

eksctl create cluster -f cluster.yaml

复制

因为使用的是已存在的VPC,所以要给subnet手动打上对应的tag

kubernetes.io/cluster/eks-test-01标签设置为shared或owned
kubernetes.io/role/internal-elb标记设置1为专用子网
kubernetes.io/role/elb设置1为公共子网的标记

复制

Pod的网络只需要打上一个tag就可以了

kubernetes.io/cluster/eks-test-01标签设置为shared或owned

复制

配置ENIconfig 规则

使用这种架构,我们把10段的网络分配给了 node节点与一些aws托管的服务例如(elb),而192段的网络分配给了pod节点,这样就需要单独配置一下ENIconfig 的规则,让pod网络可以使用我们创建的192段的网络

# 在aws-node 中配置AWS_VPC_K8S_CNI_CUSTOM_NETWORK_CFG为true
kubectl set env daemonset aws-node -n kube-system AWS_VPC_K8S_CNI_CUSTOM_NETWORK_CFG=true
# worker node为多可用区时,让 Kubernetes 自动为worker node的 ENIConfig 应用相应的 可用区,配合BootstrapArguments 参数
kubectl set env daemonset aws-node -n kube-system ENI_CONFIG_LABEL_DEF=failure-domain.beta.kubernetes.io/zone

复制

创建一个默认的安全组,这个安全组会被附加给所有的node节点与eni配置,修改入口规则,让他们允许对应网段,并记录sg-id

10.83.40.0/21
192.163.0.0/16

复制

添加 对应的规则 us-west-2-eni.yaml

apiVersion: crd.k8s.amazonaws.com/v1alpha1
kind: ENIConfig
metadata:
  name: us-west-2a
spec:
  securityGroups:
    - sg-xxxxx
  subnet: subnet-xxxxxx
---
apiVersion: crd.k8s.amazonaws.com/v1alpha1
kind: ENIConfig
metadata:
  name: us-west-2b
spec:
  securityGroups:
    - sg-xxx
  subnet: subnet-xxxx

复制

应用他们

kubectl apply -f us-west-2-eni.yaml

复制

创建nodegroup

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig


metadata:
  name: eks-test-01
  region: us-west-2


vpc:
  id: "vpc-xxxxxxxxx"
  subnets:
    private:
      us-west-2a:
          id: "subnet-xxxxxxxx"
      us-west-2b:
          id: "subnet-xxxxxxxx"
    public:
      us-west-2a:
          id: "subnet-xxxxxxxx"
      us-west-2b:
          id: "subnet-xxxxxxxx"
nodeGroups:
  # 基础设施节点
  - name: inf-t3-large    ##nodegroup名字
    labels:
      nodetype: inf
    instanceType: t3.large   ##计划使用的EC2类型
    minSize: 1      ##autoscaling 最小值
    desiredCapacity: 1  ##autoscaling 常规值
    maxSize: 6 ##autoscaling 最大值
    volumeSize: 30 ##系统系统盘大小
    volumeType: gp2 ##系统盘类型
    availabilityZones: ["us-west-2a","us-west-2b"##nodegroup所在AZ
    privateNetworking: true
    securityGroups:
      withShared: true
      withLocal: true
      attachIDs: ["sg-xxxx"]
    ssh:
      publicKeyName: 'xxxx'  ##可以ssh到worker的key名字
    tags:
      Project: Devops ##tag
      k8s.io/cluster-autoscaler/enabled: "true"
      k8s.io/cluster-autoscaler/ap-southeast-1-eks-prod: owned
      k8s.io/cluster-autoscaler/node-template/label/nodetype: inf
      k8s.io/cluster-autoscaler/node-template/taint/inf: "true:NoSchedule"
    taints:
      inf: "true:NoSchedule"
    iam:
      withAddonPolicies:
        #imageBuilder: true
        autoScaler: true
        externalDNS: true
        #certManager: true
        #appMesh: true
        ebs: true
        #fsx: true
        efs: true
        albIngress: true
        #xRay: true
        cloudWatch: true

复制

接来下维护nodegroup 都使用eksctl 配合 yaml的方式进行添加或者删除

eksctl create nodegroup --config-file cluster.yml --include=inf-t3-large
eksctl drain nodegroup --cluster=eks-test-01 --name=inf-t3-large
eksctl delete  nodegroup --cluster=eks-test-01 --name=inf-t3-large

复制



文章转载自耶喝运维,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论