aws eks 创建使用ipv6地址集群的过程和注意事项

参考资料

  • https://docs.aws.amazon.com/zh_cn/eks/latest/userguide/cni-ipv6.html
  • https://cn-north-1.console.amazonaws.cn/systems-manager/documents/AWSSupport-TroubleshootEKSWorkerNode/description?region=cn-north-1

在创建eks集群时可以指定ip地址的类型,由于eks不支持双堆栈,因此只能选择ipv4或ipv6

在这里插入图片描述

集群的ip类型在集群创建之后无法修改

对于ipv6集群的一些注意事项如下

  • 使用>=1.21版本的集群
  • 使用>=1.10.1版本的vpc-cni插件
  • 不支持windows pods和service
  • 必须开启[前缀分配
  • 子网必须同时指定ipv4和ipv6的cidr(不能只有ipv6)
  • 子网必须开启自动分配ipv6地址
  • 子网路由表必须有 IPv6 的路由
  • 安全组必须允许 IPv6 地址
  • 实例必须基于Nitro架构
  • 无法使用pod安全组
  • 无法使用自定义联网
  • vpc内通信pod转换为节点的ipv4地址,与vpc外通信并不会转换为节点ipv6而是直接走igw或eigw
  • 节点需要同时分配 IPv4IPv6
  • 为节点附加额外权限AmazonEKS_CNI_IPv6_Policy
  • 不支持luster fsx
  • 不支持ec2的ipv6元数据
  • 不能使用calico网络策略
  • 自管理节点需要在bootstrap中手动指定--service-ipv6-cidr参数

创建网络环境

创建具备ipv6 cidr的vpc,或者向现有vpc中增加ipv6 cidr块

在vpc中创建具备ipv6cidr块的子网

在这里插入图片描述

开启两个子网的自动分配ipv6地址

在这里插入图片描述

使用默认配置创建的公有路由表如下,可见ipv4也需要访问公网

在这里插入图片描述

将两个子网和带有eigw路由的路由表绑定

在这里插入图片描述

创建ipv6的eks集群

eksctl工具已经具备了ipv6 family的支持,只需要增加kubernetesNetworkConfig配置即可

https://eksctl.io/usage/vpc-ip-family/

使用eksctl创建集群,使用公私混合模式(节点使用集群私有ip访问)

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: testipv6
  region: cn-north-1
  version: "1.23"
iam:
  withOIDC: true
vpc:
  clusterEndpoints:
    publicAccess:  true
    privateAccess: true
  id: "vpc-0exxxxxxxxxxca4"
  subnets:
    private:
      private1:
          id: "subnet-012xxxxxxxxb0cd2"
      private2:
          id: "subnet-079xxxxxxxxxb3924"

kubernetesNetworkConfig:
  ipFamily: IPv6

managedNodeGroups:
  - name: testipv6-ng-1
    instanceType: m5.2xlarge
    desiredCapacity: 2
    maxSize: 3
    minSize: 0
    volumeSize: 30
    volumeType: gp3
    privateNetworking: true
    ssh:
      allow: true
      publicKeyName: cluster-key

addons:
  - name: vpc-cni
    version: latest
  - name: coredns
    version: latest
  - name: kube-proxy
    version: latest

创建完毕后查看集群的ip地址类型已经成为ipv6

在这里插入图片描述

查看节点的userdata如下

// 主要关注ipv6相关参数
/etc/eks/bootstrap.sh testipv6 --kubelet-extra-args '--node-labels=eks.amazonaws.com/sourceLaunchTemplateVersion=1,alpha.eksctl.io/cluster-name=testipv6,alpha.eksctl.io/nodegroup-name=testipv6-ng-1,eks.amazonaws.com/nodegroup-image=ami-0f59b76e038fe0fbd,eks.amazonaws.com/capacityType=ON_DEMAND,eks.amazonaws.com/nodegroup=testipv6-ng-1,eks.amazonaws.com/sourceLaunchTemplateId=lt-053a632c8ac7be031 --max-pods=110' --b64-cluster-ca $B64_CLUSTER_CA --apiserver-endpoint $API_SERVER_URL --dns-cluster-ip $K8S_CLUSTER_DNS_IP --ip-family ipv6 --service-ipv6-cidr fd3a:2866:6655::/108 --use-max-pods false

节点迟迟无法加入集群,登录节点查看kubelet日志,卡在初始化,但是没有报错,没有下载任何镜像

I0331 15:57:16.593392    5614 aws.go:1353] Building AWS cloudprovider

最终节点加入失败

在这里插入图片描述

推测是节点仍旧使用ipv4地址,但是路由表没有ipv4访问公网的路由,增加路由

在这里插入图片描述

节点成功加入集群,查看pod的ip类型已经修改为ipv6

在这里插入图片描述

进入pod中查看ip,访问ipv4使用nat gateway,访问ipv6使用eigw

bash-5.2# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet6 fe80::6c08:88ff:fe02:a385  prefixlen 64  scopeid 0x20<link>
        inet6 2400:7fc0:86de:cfab:6b35::1  prefixlen 128  scopeid 0x0<global>
        ether 6e:08:88:02:a3:85  txqueuelen 0  (Ethernet)
        RX packets 5772  bytes 30188400 (28.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4503  bytes 414367 (404.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

bash-5.2# curl cip.cc
IP      : 52.80.159.1x5 // nat的公有ip

bash-5.2# curl ip.sb
2400:7fc0:86de:cfab:6b35::1

其他和ipv6相关的测试程序

package main

import (
        "fmt"
        "net/http"
)

func main() {
        http.HandleFunc("/", hello)
        http.ListenAndServe(":8090", nil)
}

func hello(w http.ResponseWriter, r *http.Request) {
        fmt.Fprint(w, "hello wolrd\n")
}

访问ipv6服务

$ curl --interface eth0 -6 -g 'http://[fe80::3a:12ff:fe7f:2800]:8090'
$ curl --interface eth0 -6 -g 'http://[2400:7fc0:86de:cfab:6b35::2]'
posted @ 2023-04-01 01:09  zhaojie10  阅读(14)  评论(0)    收藏  举报  来源