LoginSignup
0
0

More than 1 year has passed since last update.

CalicoのPodをFargateにデプロイしない方法

Last updated at Posted at 2022-08-08

CalicoをEKS上で使うとこうなる。

$ kubectl get pod -n calico-system
NAME                                      READY   STATUS    RESTARTS   AGE
calico-node-smmgx                         0/1     Pending   0          14m
calico-node-th9f7                         1/1     Running   0          14m

FargateにデプロイされたDaemonSetのPodがPendingとなる。
これを回避する。

ポイントとしては、以下のPRがMergeされた以降のバージョンを使う点となる。
https://github.com/tigera/operator/pull/1725

現状、以下のAWSのCalicoはメンテされていない。
https://docs.aws.amazon.com/ja_jp/eks/latest/userguide/calico.html
よって、この手順でインストールしても、上述のPRがMergeされていないバージョンを使うことになる。
そのため、Calicoオフィシャルの手順を少し改変して適用する。

最初に、Calicoの最新版をインストールする。

kubectl create -f https://projectcalico.docs.tigera.io/manifests/tigera-operator.yaml

配布元がCalicoになっているものを使う。

次に、kind: Installationを作成する。このカスタムリソースはCalicoのインストール方法を定義したものとなる。Calicoオフィシャルの手順だと上手く行かなかったので、AWSで配布されていたInstallationを元に、PRの修正を反映させるための設定であるkubernetesProvider: EKSを追加する。

kubectl create -f - <<EOF
kind: Installation
apiVersion: operator.tigera.io/v1
metadata:
  name: default
spec:
  kubernetesProvider: EKS
  cni:
    type: AmazonVPC
EOF

この結果、Fargateにデプロイされなくなる。

$ kubectl get pod -n calico-system
NAME                                       READY   STATUS    RESTARTS   AGE
calico-node-4vmm7                          1/1     Running   0          35m
calico-node-54cwl                          1/1     Running   0          35m

なお、calicoのDaemonSetの中身を見ると、以下のnodeAffinityが追加設定されていることがわかる。

$ kubectl get ds -o yaml -n calico-system calico-node
:(省略)
      spec:
        affinity:
          nodeAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
              nodeSelectorTerms:
              - matchExpressions:
                - key: eks.amazonaws.com/compute-type
                  operator: NotIn
                  values:
                  - fargate
:(省略)

おまけ:動作確認

Calicoの導入理由はEKS上でNetworkPolicyを使いたかったからであり、NetworkPolicyが動作するかを確認する。
以下の動作確認用のPodとNetworkPolicyを作成する。

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: centos
  name: centos
  namespace: default
spec:
  containers:
  - command:
    - sleep
    - 365d
    image: centos
    name: centos
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: test-netpol
  namespace: default
spec:
  podSelector:
    matchLabels:
      run: centos
  policyTypes:
  - Egress
  egress:
  - to:
    - ipBlock:
        cidr: 10.10.0.0/16

実際に外部への通信が遮断されることを確認する。

$ kubectl exec -it centos -n default -- ping www.google.com
ping: www.google.com: Name or service not known
command terminated with exit code 2

NetworkPolicyを削除すると通信できることも確認する。

$ kubectl delete netpol test-netpol -n default
networkpolicy.networking.k8s.io "test-netpol" deleted
$ kubectl exec -it centos -n default -- ping www.google.com
PING www.google.com (172.253.115.103) 56(84) bytes of data.
64 bytes from bg-in-f103.1e100.net (172.253.115.103): icmp_seq=1 ttl=95 time=2.18 ms
64 bytes from bg-in-f103.1e100.net (172.253.115.103): icmp_seq=2 ttl=95 time=2.12 ms

正常にCalicoが動作しているようだ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0