0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

kindで作成したKubernetesクラスタにCiliumをインストールし、NetworkPolicyの挙動を確かめる

Last updated at Posted at 2025-12-08

はじめに

CiliumはCNIの一種で、eBPFというLinuxカーネルの機能を用いて、ネットワーク接続、保護、監視などの機能を提供するオープンソースソフトウェアです。
https://cilium.io/

サービスメッシュ、メトリクスやトレーシング、Ingress / Egress Gatewayなどさまざまな機能がありますが、今回はNetworkPolicyの機能に注目します。
https://cilium.io/use-cases/network-policy/

本記事では、kindを用いて作成したKubernetesクラスタにCiliumをインストールして、NetworkPolicyの挙動を確認してみます。

環境情報

Component Version
PC M1 MacBook Pro
OS macOS 26.1
Docker Desktop 4.54.0
kind v0.30.0
helm v4.0.1
Cilium 1.18.4

手順

Kubernetesクラスタを作成する

kindコマンドでsandboxというKubernetesクラスタを立ち上げます。
ポイントはkindnetというデフォルトのCNIプラクグインを無効にすることです。

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: sandbox
nodes:
- role: control-plane
- role: worker
- role: worker
networking:
  disableDefaultCNI: true

上記のyamlファイルを元にKubernetesクラスタを作成します。

kind create cluster --config kind-sandbox.yaml

CNIがインストールされていないので、NodeのSTATUSがNotReadyになります。

kubectl get node
NAME                    STATUS     ROLES           AGE     VERSION
sandbox-control-plane   NotReady   control-plane   8m6s    v1.34.0
sandbox-worker          NotReady   <none>          7m52s   v1.34.0
sandbox-worker2         NotReady   <none>          7m52s   v1.34.0

Ciliumをインストールする

helmでインストールします。

helm repo add cilium https://helm.cilium.io/
helm install sandbox-cilium cilium/cilium --version 1.18.4 -n cilium --create-namespace

CiliumがCNIに設定されているかは、ノードの /etc/cni/net.d/ ディレクトリで確認できます。

docker ps --format "table {{.Names}}"  
docker exec -it sandbox-control-plane ls -l /etc/cni/net.d/

疎通確認用のpodを作成する

policy-test namespaceにnginx podとclient podを作成します

echo "setup nginx pod and client pod"
kubectl create ns policy-test
kubectl run nginx --image=nginx --labels="app=nginx" -n policy-test
kubectl run client --image=curlimages/curl --labels="app=client" -n policy-test -- sleep infinity
kubectl wait --for=condition=Ready pods --all -n policy-test --timeout=10s

NetworkPolicyが無い状態での疎通確認

NetworkPolicyを設定しない状態でcurlで疎通確認します。
この状態ではHTMLが表示されるので、疎通できていることがわかります。

NGINX_IP=$(kubectl get pod nginx -n policy-test -o jsonpath='{.status.podIP}')
kubectl exec -it client -n policy-test -- curl -m 3 $NGINX_IP

全てのIngressを拒否するNetworkPolicyを設定する

policy-test namespaceにIngressの通信を拒否 (deny) するNetworkPolicyを追加します。

deny-all.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny
  namespace: policy-test
spec:
  podSelector: {}
  policyTypes:
  - Ingress

上記のマニフェストを適用して疎通確認します。
今度はエラーが発生するため、疎通できないことがわかります。

kubectl apply -f deny-all.yaml -n policy-test
kubectl exec -it client -n policy-test -- curl -m 3 $NGINX_IP

nginx podからclient podへの疎通を許可するNetworkPolicyを設定する

nginxからclientへの疎通を許可 (allow) するNetworkPolicyを設定します。

allow-nginx.yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-client-accsss
  namespace: policy-test
spec:
  podSelector:
    matchLabels:
      app: nginx
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          app: client
    ports:
    - protocol: TCP
      port: 80

同じくマニフェストを適用して疎通確認します。
再びHTMLが表示されたので、疎通できていることがわかります。

kubectl apply -f allow-nginx.yaml -n policy-test
kubectl exec -it client -n policy-test -- curl -m 3 $NGINX_IP

最後に

kindを用いて作成したKubernetesクラスタにCiliumをインストールして、NetworkPolicyの挙動を確認できました。

参考情報

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?