AWS_VPC_K8S_CNI_EXTERNALSNATの挙動を確認する

AWS_VPC_K8S_CNI_EXTERNALSNATの理解に苦しんだので、確認したメモ。

コンポーネント バージョン
EKS 1.21
プラットフォームバージョン eks.3
eksctl 0.75.0
aws-node v1.7.5-eksbuild.1

クラスターの作成

1.21でクラスターを作成する。ノードなしで作成する。

CLUSTER_NAME="externalsnat"
cat << EOF > cluster.yaml
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: ${CLUSTER_NAME}
  region: ap-northeast-1
  version: "1.21"
vpc:
  cidr: "10.0.0.0/16"

availabilityZones:
  - ap-northeast-1a
  - ap-northeast-1c

cloudWatch:
  clusterLogging:
    enableTypes: ["*"]

iam:
  withOIDC: true
EOF
eksctl create cluster -f cluster.yaml

ノードを作成する。

CLUSTER_NAME="externalsnat"
cat << EOF > managed-ng-1.yaml
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: ${CLUSTER_NAME}
  region: ap-northeast-1

managedNodeGroups:
  - name: managed-ng-1
    minSize: 1
    maxSize: 1
    desiredCapacity: 1
    privateNetworking: true
    iam:
      attachPolicyARNs:
        - arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
        - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
        - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
EOF
eksctl create nodegroup -f managed-ng-1.yaml

Adminロールにも権限をつけておく。

CLUSTER_NAME="externalsnat"
USER_NAME="Admin:{{SessionName}}"
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --output text --query Account)
ROLE_ARN="arn:aws:iam::${AWS_ACCOUNT_ID}:role/Admin"
eksctl create iamidentitymapping --cluster ${CLUSTER_NAME} --arn ${ROLE_ARN} --username ${USER_NAME} --group system:masters

aws-nodeのバージョンはv1.7.5で、AWS_VPC_K8S_CNI_EXTERNALSNATfalseになっている。

$ k -n kube-system get ds aws-node -o yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
(省略)
  name: aws-node
  namespace: kube-system
(省略)
spec:
(省略)
  template:
(省略)
    spec:
(省略)
      containers:
      - env:
        - name: ADDITIONAL_ENI_TAGS
          value: '{}'
        - name: AWS_VPC_CNI_NODE_PORT_SUPPORT
          value: "true"
        - name: AWS_VPC_ENI_MTU
          value: "9001"
        - name: AWS_VPC_K8S_CNI_CONFIGURE_RPFILTER
          value: "false"
        - name: AWS_VPC_K8S_CNI_CUSTOM_NETWORK_CFG
          value: "false"
        - name: AWS_VPC_K8S_CNI_EXTERNALSNAT
          value: "false"
        - name: AWS_VPC_K8S_CNI_LOGLEVEL
          value: DEBUG
        - name: AWS_VPC_K8S_CNI_LOG_FILE
          value: /host/var/log/aws-routed-eni/ipamd.log
        - name: AWS_VPC_K8S_CNI_RANDOMIZESNAT
          value: prng
        - name: AWS_VPC_K8S_CNI_VETHPREFIX
          value: eni
        - name: AWS_VPC_K8S_PLUGIN_LOG_FILE
          value: /var/log/aws-routed-eni/plugin.log
        - name: AWS_VPC_K8S_PLUGIN_LOG_LEVEL
          value: DEBUG
        - name: DISABLE_INTROSPECTION
          value: "false"
        - name: DISABLE_METRICS
          value: "false"
        - name: ENABLE_POD_ENI
          value: "false"
        - name: MY_NODE_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.nodeName
        - name: WARM_ENI_TARGET
          value: "1"
        image: 602401143452.dkr.ecr.ap-northeast-1.amazonaws.com/amazon-k8s-cni:v1.7.5-eksbuild.1
        imagePullPolicy: Always
        livenessProbe:
          exec:
            command:
            - /app/grpc-health-probe
            - -addr=:50051
          failureThreshold: 3
          initialDelaySeconds: 60
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        name: aws-node
(省略)

検証準備

クラスターを作成したVPC-A内にテスト用のインスタンスA(10.0.64.94)を立てる。

VPC-Bを作成してVPCピアリングをして、インスタンスB(10.1.1.235)を立てる。

セキュリティグループを注意して設定する。

詳細は省略。

検証

まずインスタンスAとインスタンスBからワーカーノードに接続できることを確認する。

ノードを確認する。

$ k get node -o wide
NAME                                              STATUS   ROLES    AGE   VERSION               INTERNAL-IP    EXTERNAL-IP   OS-IMAGE         KERNEL-VERSION                CONTAINER-RUNTIME
ip-10-0-120-188.ap-northeast-1.compute.internal   Ready    <none>   57m   v1.21.5-eks-bc4871b   10.0.120.188   <none>        Amazon Linux 2   5.4.156-83.273.amzn2.x86_64   docker://20.10.7

インスタンスAからワーカーノード(10.0.120.188)にpingSSHをしてみる。接続できる。

[root@ip-10-0-64-94 ~]# ping 10.0.120.188
PING 10.0.120.188 (10.0.120.188) 56(84) bytes of data.
64 bytes from 10.0.120.188: icmp_seq=1 ttl=255 time=1.59 ms
64 bytes from 10.0.120.188: icmp_seq=2 ttl=255 time=1.62 ms
^C
--- 10.0.120.188 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 1.597/1.610/1.623/0.013 ms
[root@ip-10-0-64-94 ~]# ssh 10.0.120.188
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
[root@ip-10-0-64-94 ~]#

インスタンスBから同じことを試す。接続できる。

[root@ip-10-1-1-235 ~]# ping 10.0.120.188
PING 10.0.120.188 (10.0.120.188) 56(84) bytes of data.
64 bytes from 10.0.120.188: icmp_seq=1 ttl=255 time=0.948 ms
64 bytes from 10.0.120.188: icmp_seq=2 ttl=255 time=0.941 ms
64 bytes from 10.0.120.188: icmp_seq=3 ttl=255 time=0.954 ms
^C
--- 10.0.120.188 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.941/0.947/0.954/0.035 ms
[root@ip-10-1-1-235 ~]# ssh 10.0.120.188
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
[root@ip-10-1-1-235 ~]#

AWS_VPC_K8S_CNI_EXTERNALSNAT=false

NginxのPodを実行する。

$ k create deployment nginx --image=nginx --port 80
deployment.apps/nginx created
$ k get po -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP             NODE                                              NOMINATED NODE   READINESS GATES
nginx-7848d4b86f-h6p6v   1/1     Running   0          18s   10.0.102.179   ip-10-0-120-188.ap-northeast-1.compute.internal   <none>           <none>

インスタンスAからPod(10.0.102.179)にpingcurlをしてみる。接続できる。

[root@ip-10-0-64-94 ~]# ping 10.0.102.179
PING 10.0.102.179 (10.0.102.179) 56(84) bytes of data.
64 bytes from 10.0.102.179: icmp_seq=1 ttl=254 time=1.60 ms
64 bytes from 10.0.102.179: icmp_seq=2 ttl=254 time=1.63 ms
64 bytes from 10.0.102.179: icmp_seq=3 ttl=254 time=1.61 ms
^C
--- 10.0.102.179 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.609/1.619/1.632/0.034 ms
[root@ip-10-0-64-94 ~]# curl http://10.0.102.179
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@ip-10-0-64-94 ~]#

インスタンスBから同じことを試す。接続できる。

[root@ip-10-1-1-235 ~]# ping 10.0.102.179
PING 10.0.102.179 (10.0.102.179) 56(84) bytes of data.
64 bytes from 10.0.102.179: icmp_seq=1 ttl=254 time=0.974 ms
64 bytes from 10.0.102.179: icmp_seq=2 ttl=254 time=0.966 ms
64 bytes from 10.0.102.179: icmp_seq=3 ttl=254 time=0.955 ms
^C
--- 10.0.102.179 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.955/0.965/0.974/0.007 ms
[root@ip-10-1-1-235 ~]# curl http://10.0.102.179
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@ip-10-1-1-235 ~]#

VPC-Bからだと繋がらないのではと予想していたので、予想と違った。このケースでは、PodのIPの10.0.102.179はプライマリーENI(eth0)のセカンダリーIPを使っていた。

f:id:sotoiwa:20211202163915p:plain

f:id:sotoiwa:20211202163539p:plain

セカンダリーENIのIPを使うPodで試したいので、Podをスケールさせる。

$ k scale deploy nginx --replicas=5
deployment.apps/nginx scaled
$ k get po -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP             NODE                                              NOMINATED NODE   READINESS GATES
nginx-7848d4b86f-7b599   1/1     Running   0          5s    10.0.97.245    ip-10-0-120-188.ap-northeast-1.compute.internal   <none>           <none>
nginx-7848d4b86f-c7v5d   1/1     Running   0          5s    10.0.113.95    ip-10-0-120-188.ap-northeast-1.compute.internal   <none>           <none>
nginx-7848d4b86f-kl68s   1/1     Running   0          5s    10.0.102.179   ip-10-0-120-188.ap-northeast-1.compute.internal   <none>           <none>
nginx-7848d4b86f-mgwcz   1/1     Running   0          5s    10.0.101.9     ip-10-0-120-188.ap-northeast-1.compute.internal   <none>           <none>
nginx-7848d4b86f-rfmjt   1/1     Running   0          41s   10.0.100.168   ip-10-0-120-188.ap-northeast-1.compute.internal   <none>           <none>

10.0.97.245セカンダリーENIのセカンダリーIPであることを確認する。このIPを使っているPodに対して先ほどを同じことを試す。

f:id:sotoiwa:20211202163603p:plain

インスタンスAからは接続できる。

[root@ip-10-0-64-94 ~]# ping 10.0.97.245
PING 10.0.97.245 (10.0.97.245) 56(84) bytes of data.
64 bytes from 10.0.97.245: icmp_seq=1 ttl=254 time=2.46 ms
64 bytes from 10.0.97.245: icmp_seq=2 ttl=254 time=1.65 ms
64 bytes from 10.0.97.245: icmp_seq=3 ttl=254 time=1.64 ms
^C
--- 10.0.97.245 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.642/1.921/2.467/0.386 ms
[root@ip-10-0-64-94 ~]# curl http://10.0.97.245
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@ip-10-0-64-94 ~]#

インスタンスBからは接続できない!

[root@ip-10-1-1-235 ~]# ping 10.0.97.24
PING 10.0.97.24 (10.0.97.24) 56(84) bytes of data.
^C
--- 10.0.97.24 ping statistics ---
9 packets transmitted, 0 received, 100% packet loss, time 8190ms

[root@ip-10-1-1-235 ~]# curl http://10.0.97.24
^C
[root@ip-10-1-1-235 ~]#

PodがSYNが受け取れないのか、あるいは応答のパケットがドロップされてしまうのか、よくわからないがとにかく受け取れない。

逆向きの接続を確認する。

eth0で動作しているPod(10.0.102.179)に入り、sshをインストールする。

k exec -it nginx-7848d4b86f-kl68s -- bash
apt-get update
apt-get install -y ssh

インスタンスA(10.0.64.94)とインスタンスB(10.1.1.235)に接続できるか試す。接続できる。

root@nginx-7848d4b86f-kl68s:/# ssh 10.0.64.94
The authenticity of host '10.0.64.94 (10.0.64.94)' can't be established.
ECDSA key fingerprint is SHA256:jXESh6EUOBjg4lUkLMXAKqNR5b2isnIVGb5q7cYyfDM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.64.94' (ECDSA) to the list of known hosts.
root@10.0.64.94: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
root@nginx-7848d4b86f-kl68s:/# ssh 10.1.1.235
The authenticity of host '10.1.1.235 (10.1.1.235)' can't be established.
ECDSA key fingerprint is SHA256:WHQiCxG2mqCvMLe0WmHaWkB6WzRLsyXpcgbeEoZ0xDc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.1.1.235' (ECDSA) to the list of known hosts.
root@10.1.1.235: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
root@nginx-7848d4b86f-kl68s:/#

インスタンスAの/var/log/secureを確認する。PodのIPからきている。

Dec  2 06:43:41 ip-10-0-64-94 sshd[31718]: Connection closed by 10.0.102.179 port 44918 [preauth]

インスタンスBの/var/log/secureを確認する。ノードのIPからきている。つまりSNATされている。

Dec  2 06:43:16 ip-10-1-1-235 sshd[31625]: Connection closed by 10.0.120.188 port 29262 [preauth]

eth1で動作しているPod(10.0.97.245)に入り、sshをインストールする。

k exec -it nginx-7848d4b86f-7b599 -- bash
apt-get update
apt-get install -y ssh

インスタンスA(10.0.64.94)とインスタンスB(10.1.1.235)に接続できるか試す。接続できる。

root@nginx-7848d4b86f-7b599:/# ssh 10.0.64.94
The authenticity of host '10.0.64.94 (10.0.64.94)' can't be established.
ECDSA key fingerprint is SHA256:jXESh6EUOBjg4lUkLMXAKqNR5b2isnIVGb5q7cYyfDM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.0.64.94' (ECDSA) to the list of known hosts.
root@10.0.64.94: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
root@nginx-7848d4b86f-7b599:/# ssh 10.1.1.235
The authenticity of host '10.1.1.235 (10.1.1.235)' can't be established.
ECDSA key fingerprint is SHA256:WHQiCxG2mqCvMLe0WmHaWkB6WzRLsyXpcgbeEoZ0xDc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.1.1.235' (ECDSA) to the list of known hosts.
root@10.1.1.235: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
root@nginx-7848d4b86f-7b599:/#

インスタンスAの/var/log/secureを確認する。PodのIPからきている。

Dec  2 07:02:37 ip-10-0-64-94 sshd[31806]: Connection closed by 10.0.97.245 port 37228 [preauth]

インスタンスBの/var/log/secureを確認する。ノードのIPからきている。つまりSNATされている。

Dec  2 07:02:45 ip-10-1-1-235 sshd[31720]: Connection closed by 10.0.120.188 port 23626 [preauth]

AWS_VPC_K8S_CNI_EXTERNALSNAT=true

設定を変更する。

kubectl set env daemonset -n kube-system aws-node AWS_VPC_K8S_CNI_EXTERNALSNAT=true

aws-nodeが再起動されたことを確認する。

$ k get po -n kube-system
NAME                       READY   STATUS    RESTARTS   AGE
aws-node-qxdx4             1/1     Running   0          24s
coredns-76f4967988-85t4h   1/1     Running   0          133m
coredns-76f4967988-cmtl7   1/1     Running   0          133m
kube-proxy-b5lq5           1/1     Running   0          120m

インスタンスAからeth0で稼働するPodにpingcurlをしてみる。接続できる。

[root@ip-10-0-64-94 ~]# ping 10.0.102.179
PING 10.0.102.179 (10.0.102.179) 56(84) bytes of data.
64 bytes from 10.0.102.179: icmp_seq=1 ttl=254 time=1.62 ms
64 bytes from 10.0.102.179: icmp_seq=2 ttl=254 time=1.59 ms
64 bytes from 10.0.102.179: icmp_seq=3 ttl=254 time=1.59 ms
^C
--- 10.0.102.179 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.593/1.602/1.620/0.012 ms
[root@ip-10-0-64-94 ~]# curl http://10.0.102.179
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@ip-10-0-64-94 ~]#

インスタンスBから同じことを試す。接続できる。

[root@ip-10-1-1-235 ~]# ping 10.0.102.179
PING 10.0.102.179 (10.0.102.179) 56(84) bytes of data.
64 bytes from 10.0.102.179: icmp_seq=1 ttl=254 time=0.971 ms
64 bytes from 10.0.102.179: icmp_seq=2 ttl=254 time=0.971 ms
64 bytes from 10.0.102.179: icmp_seq=3 ttl=254 time=0.960 ms
^C
--- 10.0.102.179 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.960/0.967/0.971/0.025 ms
[root@ip-10-1-1-235 ~]# curl http://10.0.102.179
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@ip-10-1-1-235 ~]#

インスタンスAからeth1で稼働するPodにpingcurlをしてみる。接続できる。

[root@ip-10-0-64-94 ~]# ping 10.0.97.245
PING 10.0.97.245 (10.0.97.245) 56(84) bytes of data.
64 bytes from 10.0.97.245: icmp_seq=1 ttl=254 time=1.66 ms
64 bytes from 10.0.97.245: icmp_seq=2 ttl=254 time=1.60 ms
64 bytes from 10.0.97.245: icmp_seq=3 ttl=254 time=1.61 ms
^C
--- 10.0.97.245 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.607/1.626/1.662/0.052 ms
[root@ip-10-0-64-94 ~]# curl http://10.0.97.245
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@ip-10-0-64-94 ~]#

インスタンスBから同じことを試す。接続できるようになった!

[root@ip-10-1-1-235 ~]# ping 10.0.97.245
PING 10.0.97.245 (10.0.97.245) 56(84) bytes of data.
64 bytes from 10.0.97.245: icmp_seq=1 ttl=254 time=0.967 ms
64 bytes from 10.0.97.245: icmp_seq=2 ttl=254 time=0.973 ms
64 bytes from 10.0.97.245: icmp_seq=3 ttl=254 time=0.950 ms
^C
--- 10.0.97.245 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.950/0.963/0.973/0.027 ms
[root@ip-10-1-1-235 ~]# curl http://10.0.97.245
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@ip-10-1-1-235 ~]#

eth0で動作しているPod(10.0.102.179)に入り、インスタンスA(10.0.64.94)とインスタンスB(10.1.1.235)に接続できるか試す。接続できる。

$ k exec -it nginx-7848d4b86f-kl68s -- bash
root@nginx-7848d4b86f-kl68s:/# ssh 10.0.64.94
root@10.0.64.94: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
root@nginx-7848d4b86f-kl68s:/# ssh 10.1.1.235
root@10.1.1.235: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
root@nginx-7848d4b86f-kl68s:/#

インスタンスAの/var/log/secureを確認する。PodのIPからきている。

Dec  2 07:15:23 ip-10-0-64-94 sshd[31835]: Connection closed by 10.0.102.179 port 34644 [preauth]

インスタンスBの/var/log/secureを確認する。PodのIPからきている。

Dec  2 07:15:38 ip-10-1-1-235 sshd[31786]: Connection closed by 10.0.102.179 port 39066 [preauth]

eth1で動作しているPod(10.0.97.245)に入り、インスタンスA(10.0.64.94)とインスタンスB(10.1.1.235)に接続できるか試す。接続できる。

$ k exec -it nginx-7848d4b86f-7b599 -- bash
root@nginx-7848d4b86f-7b599:/# ssh 10.0.64.94
root@10.0.64.94: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
root@nginx-7848d4b86f-7b599:/# ssh 10.1.1.235
root@10.1.1.235: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
root@nginx-7848d4b86f-7b599:/#

インスタンスAの/var/log/secureを確認する。PodのIPからきている。

Dec  2 07:18:19 ip-10-0-64-94 sshd[31883]: Connection closed by 10.0.97.245 port 46196 [preauth]

インスタンスBの/var/log/secureを確認する。PodのIPからきている。

Dec  2 07:19:14 ip-10-1-1-235 sshd[31796]: Connection closed by 10.0.97.245 port 50710 [preauth]

まとめ

  • AWS_VPC_K8S_CNI_EXTERNALSNAT=falseの場合、VPC外に出て行くときにSNATが行われる
  • AWS_VPC_K8S_CNI_EXTERNALSNAT=falseの場合、VPC外からセカンダリーENI上で動いているPodに接続できない

AWS_VPC_K8S_CNI_EXTERNALSNAT=falseの場合

接続元 接続先 結果
同じVPCインスタンス プライマリーENI上のPod 接続できる
同じVPCインスタンス セカンダリーENI上のPod 接続できる
ピアリングしたVPCインスタンス プライマリーENI上のPod 接続できる
ピアリングしたVPCインスタンス セカンダリーENI上のPod 接続できない
プライマリーENI上のPod 同じVPCインスタンス 接続できる(SNATされないのでソースはPodのIP)
プライマリーENI上のPod ピアリングしたVPCインスタンス 接続できる(SNATされるのでソースはノードのIP)

AWS_VPC_K8S_CNI_EXTERNALSNAT=trueの場合

接続元 接続先 結果
同じVPCインスタンス プライマリーENI上のPod 接続できる
同じVPCインスタンス セカンダリーENI上のPod 接続できる
ピアリングしたVPCインスタンス プライマリーENI上のPod 接続できる
ピアリングしたVPCインスタンス セカンダリーENI上のPod 接続できる
プライマリーENI上のPod 同じVPCインスタンス 接続できる(SNATされないのでソースはPodのIP)
プライマリーENI上のPod ピアリングしたVPCインスタンス 接続できる(SNATされないのでソースはPodのIP)