AWS announces preview of AWS Interconnect - multicloud
AWS announces AWS Interconnect – multicloud (preview), providing simple, resilient, high-speed private connections to other cloud service providers. AWS Interconnect - multicloud is easy to configure and provides high-speed, resilient connectivity with dedicated bandwidth, enabling customers to interconnect AWS networking services such as AWS Transit Gateway, AWS Cloud WAN, and Amazon VPC to other cloud service providers with ease.
如何为 Amazon EKS containerd 节点自动配置 HTTP 代理?
我想为具有 containerd 运行时的 Amazon Elastic Kubernetes Service(Amazon EKS)节点自动配置 HTTP 代理。
简短描述
在 Amazon EKS 1.23 或更早版本中创建的托管节点组,其默认容器运行时为 Docker。如果这是您的使用案例,请按照决议中的所有步骤指定容器运行时。对于在 Amazon EKS 版本 1.24 或更高版本中创建的托管节点组,默认容器运行时为 containerd。
若要在托管节点组中使用 containerd 而不是 dockerd,您必须在 userdata 中指定 containerd 运行时。
在将托管节点组切换到 containerd 运行时后,使用您的亚马逊机器映像(AMI)ID 创建自定义启动模板。然后,配置 HTTP 代理的设置和集群环境值。
**注意:**对于使用Docker作为运行时的节点,请参阅如何为使用Docker的Amazon EKS工作节点自动配置HTTP代理?
解决方法
创建自定义启动模板
要指定 containerd 作为运行时并创建自定义启动模板,请完成以下步骤:
-
在您的托管节点组中将 containerd 指定为运行时。在 userdata 中,为 bootstrap.sh 使用 --container-runtime=containerd 选项。
-
使用 AMI ID 创建自定义启动模板。如果您不这样做,则托管节点组会自动合并 userdata。
-
将代理配置设置为 containerd、sandbox-image 和 kubelet。
**注意:**Sandbox-image 是为 containerd 拉动沙盒映像的服务单元。 -
使用以下字段描述 userdata:
MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==BOUNDARY==" --==BOUNDARY== Content-Type: text/cloud-boothook; charset="us-ascii" #Set the proxy hostname and port PROXY=XXXXXXX:3128 TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` MAC=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -v -s http://169.254.169.254/latest/meta-data/mac/) VPC_CIDR=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -v -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/vpc-ipv4-cidr-blocks | xargs | tr ' ' ',') #Create the containerd and sandbox-image systemd directory mkdir -p /etc/systemd/system/containerd.service.d mkdir -p /etc/systemd/system/sandbox-image.service.d #[Option] Configure yum to use the proxy cloud-init-per instance yum_proxy_config cat << EOF >> /etc/yum.conf proxy=http://$PROXY EOF #Set the proxy for future processes, and use as an include file cloud-init-per instance proxy_config cat << EOF >> /etc/environment http_proxy=http://$PROXY https_proxy=http://$PROXY HTTP_PROXY=http://$PROXY HTTPS_PROXY=http://$PROXY no_proxy=$VPC_CIDR,localhost,127.0.0.1,169.254.169.254,.internal,.eks.amazonaws.com NO_PROXY=$VPC_CIDR,localhost,127.0.0.1,169.254.169.254,.internal,.eks.amazonaws.com EOF #Configure Containerd with the proxy cloud-init-per instance containerd_proxy_config tee <<EOF /etc/systemd/system/containerd.service.d/http-proxy.conf >/dev/null [Service] EnvironmentFile=/etc/environment EOF #Configure sandbox-image with the proxy cloud-init-per instance sandbox-image_proxy_config tee <<EOF /etc/systemd/system/sandbox-image.service.d/http-proxy.conf >/dev/null [Service] EnvironmentFile=/etc/environment EOF #Configure the kubelet with the proxy cloud-init-per instance kubelet_proxy_config tee <<EOF /etc/systemd/system/kubelet.service.d/proxy.conf >/dev/null [Service] EnvironmentFile=/etc/environment EOF cloud-init-per instance reload_daemon systemctl daemon-reload --==BOUNDARY== Content-Type:text/x-shellscript; charset="us-ascii" #!/bin/bash set -o xtrace #Set the proxy variables before running the bootstrap.sh script set -a source /etc/environment #Run the bootstrap.sh script B64_CLUSTER_CA=YOUR_CLUSTER_CA API_SERVER_URL=API_SERVER_ENDPOINT /etc/eks/bootstrap.sh EKS_CLUSTER_NAME --b64-cluster-ca $B64_CLUSTER_CA --apiserver-endpoint $API_SERVER_URL --container-runtime containerd --==BOUNDARY==--**注意:**将 XXXXXXX:3128、YOUR_CLUSTER_CA、API_SERVER_ENDPOINT 和 EKS_CLUSTER_NAME 替换为您的代理、集群证书颁发机构(CA)、服务器端点和集群名称。创建虚拟私有云(VPC)端点后,将 AWS 服务端点添加到 NO_PROXY 和 no_proxy。
为 aws-node 和 kube-proxy 配置代理设置
**注意:**如果您通过 HTTP 代理将流量从集群路由到互联网,并且您的 EKS 端点是公共的,则您必须完成这些步骤。如果您有不同的配置,则这些步骤是可选的。
创建 ConfigMap 来配置环境值。然后,在您的集群中应用 ConfigMap。使用以下脚本作为 ConfigMap 示例:
apiVersion: v1 kind: ConfigMap metadata: name: proxy-environment-variables namespace: kube-system data: HTTP_PROXY: http://XXXXXXX:3128 HTTPS_PROXY: http://XXXXXXX:3128 NO_PROXY: KUBERNETES_SERVICE_CIDR_RANGE,localhost,127.0.0.1,VPC_CIDR_RANGE,169.254.169.254,.internal
**注意:**将 KUBERNETES_SERVICE_CIDR_RANGE 和 VPC_CIDR_RANGE 替换为 CIDR 范围的值。在创建其 VPC 端点后,您可以向 NO_PROXY 和 no_proxy 添加 AWS 服务端点。
然后,将 HTTP 代理配置设置为 aws-node 和 kube-proxy:
$ kubectl patch -n kube-system -p '{ "spec": {"template":{ "spec": { "containers": [ { "name": "aws-node", "envFrom": [ { "configMapRef": {"name": "proxy-environment-variables"} } ] } ] } } } }' daemonset aws-node $ kubectl patch -n kube-system -p '{ "spec": {"template":{ "spec": { "containers": [ { "name": "kube-proxy", "envFrom": [ { "configMapRef": {"name": "proxy-environment-variables"} } ] } ] } } } }' daemonset kube-proxy
创建托管节点组
使用您创建的自定义启动模板,创建新的托管节点组。
测试您的代理
若要查看您的节点状态,请运行以下命令:
$ kubectl get nodes $ kubectl run test-pod --image=amazonlinux:2 --restart=Never -- sleep 300 $ kubectl get pods -A
您收到的输出类似于以下示例:
$ kubectl get nodes -o wide NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME ip-192-168-100-114.ap-northeast-1.compute.internal Ready <none> 2m27s v1.23.13-eks-fb459a0 192.168.100.114 <none> Amazon Linux 2 5.4.219-126.411.amzn2.x86_64 containerd://1.6.6 $ kubectl run test-pod --image=amazonlinux:2 --restart=Never -- sleep 300 pod/test-pod created $ kubectl get pods -A NAMESPACE NAME READY STATUS RESTARTS AGE default test-pod 1/1 Running 0 14s kube-system aws-node-cpjcl 1/1 Running 0 3m34s kube-system coredns-69cfddc4b4-c7rpd 1/1 Running 0 26m kube-system coredns-69cfddc4b4-z5jxq 1/1 Running 0 26m kube-system kube-proxy-g2f4g 1/1 Running 0 3m34s
查看您的代理日志,了解有关节点连接的更多信息:
192.168.100.114 TCP_TUNNEL/200 6230 CONNECT registry-1.docker.io:443 - HIER_DIRECT/XX.XX.XX.XX - 192.168.100.114 TCP_TUNNEL/200 10359 CONNECT auth.docker.io:443 - HIER_DIRECT/XX.XX.XX.XX - 192.168.100.114 TCP_TUNNEL/200 6633 CONNECT registry-1.docker.io:443 - HIER_DIRECT/XX.XX.XX.XX - 192.168.100.114 TCP_TUNNEL/200 10353 CONNECT auth.docker.io:443 - HIER_DIRECT/XX.XX.XX.XX - 192.168.100.114 TCP_TUNNEL/200 8767 CONNECT registry-1.docker.io:443 - HIER_DIRECT/XX.XX.XX.XX -
相关信息
- 语言
- 中文 (简体)

相关内容
AWS 官方已更新 3 个月前