Cilium 이란?
Cilium은 eBPF(Berkeley Packet Filter)를 기반으로 구성된 CNI Plugin입니다.
Kubernetes 클러스터와 같은 컨테이너 환경을 위해 뛰어난 확장성과 효율적인 네트워크 및 보안 정책을 제공합니다.
Cilium eBPF는 추가적인 App 이나 설정 변경 없이 리눅스 커널을 자유롭게 프로그래밍하여 동작 할 수 있습니다.
또, Cilium은 iptables를 이용한 Kubernetes 트래픽 라우팅의 단점을 보완하여 네트워크 성능을 높혀줍니다.
일반적인 Linux Network Stack은 Process에서 시스템 콜을 날리면 소캣을 타고 유저 네임스페이스를 통해 네트워크 디바이스로 나갔습니다. 하지만 eBPF는 Kernel에 Sandbox 형태로 설치되기 때문에 불필요한 오버헤드를 발생하지 않고, Kernel Level에서 Packet Filter를 할 수 있습니다.
- eBPF & Cilium과 기존 구성의 비교
기능 | eBPF & Cilium | iptables & Calico |
성능 | 높음 (커널 레벨 실행) | 보통이거나 낮음 (User-space / Kernel-space trainsitions) |
유연성 | 높음(다양한 위치에서 사용자 로직) | 보통 (정의된 정책 / 기능으로 제어) |
확장성 | 대규모 확장에 효율 | 오버헤드로 인한 확장의 어려움있음 |
어플리케이션 계층(L7) | 시각화와 제어 지원 | 별도의 사이드카 패턴이 필요 |
보안 | 높음 | 구성에 따라 달라짐 |
기존에 많이 사용했던 IPTABLES의 경우 Kubernetes에서 Kube-proxy가 대신해 배포되는 Service와 Endpoint까지 또 그외 다양한 정책들을 자동으로 적용해주지만, 자동이라 하더라도 한줄 한줄 정책이 반영되는 것이기 때문에, 정책이 많아지면 당연히 성능에도 Delay가 발생하게 됩니다.
이 Delay는 특히 IPTABLES 특성으로 인해 발생하는데, 주 원인은 정책 적용이 add가 아니라 rewrite라는데에 큰 문제가 있습니다.
눈으로 보이는 IPTABLES의 정책은 한줄씩 더해지는 것 처럼 보이지만 실제는 전체 정책을 지우고, 추가되는 정책과 함께 새롭게 전체 정책을 작성해 적용합니다. 100줄 내외의 정책이 반영되기에는 적은 시간이 소요되겠지만 수천 수만 줄의 정책이 적용되는 경우 당연하게 Delay가 발생하게 됩니다.
- Cilium 아키텍처
Clium Agent : 데몬셋으로 실행, K8S API 설정으로 부터 '네트워크 설정, 네트워크 정책, 서비스 부하분산, 모니터링' 등을 수행하며, eBPF 프로그램을 관리
Cilium Client : Cilium 커맨드툴, eBPF maps에 직접 접속하여 상태를 확인할 수 있다.
Hubble : 네트워크와 보안 모니터링 플랫폼 역할을 하여, 'Server, Relay, Client, Graphical UI'로 구성되어 있다.
Data Store : Cilium Agent 간의 상태를 저장하고 전파하는 테이터 저장소, 2가지 종류 중 선택 (K8S CRDs, Key-Value Store)
실습 시작
구성 환경 : AWS VPC 1ea, EC2 4ea (k8s 3ea, testvm 1ea)
특이 사항 : 배포 스크립트 내 kube-proxy 비활성화를 위해 --skip-phases=addon/kube-proxy 추가
배포된 인스턴스 확인
$ aws ec2 describe-instances --query "Reservations[*].Instances[*].{PublicIPAdd:PublicIpAddress,InstanceName:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --filters Name=instance-state-name,Values=running --output text
k8s-w2 52.78.21.130 running
k8s-s 3.36.78.228 running
testpc 54.180.228.229 running
k8s-w1 3.39.235.9 running
Control Plane 접속 후 Cluster 내부 확인
testpc vm 접속 및 내부 확인
Helm을 통해 Cilium 배포
$ helm repo add cilium https://helm.cilium.io/
$ helm repo update
$ helm install cilium cilium/cilium --version 1.16.3 --namespace kube-system \
--set k8sServiceHost=192.168.10.10 --set k8sServicePort=6443 --set debug.enabled=true \
--set rollOutCiliumPods=true --set routingMode=native --set autoDirectNodeRoutes=true \
--set bpf.masquerade=true --set bpf.hostRouting=true --set endpointRoutes.enabled=true \
--set ipam.mode=kubernetes --set k8s.requireIPv4PodCIDR=true --set kubeProxyReplacement=true \
--set ipv4NativeRoutingCIDR=192.168.0.0/16 --set installNoConntrackIptablesRules=true \
--set hubble.ui.enabled=true --set hubble.relay.enabled=true --set prometheus.enabled=true --set operator.prometheus.enabled=true --set hubble.metrics.enableOpenMetrics=true \
--set hubble.metrics.enabled="{dns:query;ignoreAAAA,drop,tcp,flow,port-distribution,icmp,httpV2:exemplars=true;labelsContext=source_ip\,source_namespace\,source_workload\,destination_ip\,destination_namespace\,destination_workload\,traffic_direction}" \
--set operator.replicas=1
## 배포 확인
$ k get node,pod -A -o wide
- kube proxy 비활 성화로 Node Status가 Not Ready이며, Cilium 배포 후 얼마 지나지 않아, Ready 상태로 변경되었습니다.
📍 주요 파라미터 설명
--set debug.enabled=true : cilium 파드에 로그 레벨을 debug로 설정
--set autoDirectNodeRoutes=true : 동일 대역 내의 노드들 끼리는 상대 노드의 podCIDR 대역의 라우팅을 자동 설정
--set endpointRoutes.enabled=true : 호스트에 endpoint(파드)별 개별 라우팅 설정
--set hubble.relay.enabled=true --set hubble.ui.enabled=true : hubble 활성화
--set ipam.mode=kubernetes --set k8s.requireIPv4PodCIDR=true : k8s IPAM 활용
--set kubeProxyReplacement=true : kube proxy 없이 대처하도록 (최대한)
--set ipv4NativeRoutingCIDR=192.168.0.0/16 : 해당 대역과 통신 시 IP Masq 하지 않음, 보통 내부망 대역을 지정
--set operator.replicas=1 : cilium-operator 파드 기본 1개
--set enableIPv4Masquerade=true --set bpf.masquerade=true : 파드를 위한 Masquerade, 추가로 Masqerade를 BPF로 처리
설정 확인
(⎈|ciliumLab:N/A) root@k8s-s:~# ip -c addr | grep cilium
3: cilium_net@cilium_host: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 9001 qdisc noqueue state UP group default qlen 1000
4: cilium_host@cilium_net: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 9001 qdisc noqueue state UP group default qlen 1000
inet 172.16.0.109/32 scope global cilium_host
ciliumnodes
- Cilium 노드의 상태와 네트워크 정보를 조회합니다.
- CILIUMINTERNALIP : cilium_host 인터페이스의 IP 주소, cilium의 내부 통신에 사용되며 노드 간 통신과 CNI 네트워킹에 활용
ciliumendpoint
- 네임스페이스의 Cilium 엔드포인트 정보를 조회
- SECURITY_IDENTITY : cilium의 보안 식별자
(⎈|ciliumLab:N/A) root@k8s-s:~# k get crd
NAME CREATED AT
ciliumcidrgroups.cilium.io 2024-10-26T13:12:33Z
ciliumclusterwidenetworkpolicies.cilium.io 2024-10-26T13:12:35Z
ciliumendpoints.cilium.io 2024-10-26T13:12:33Z
ciliumexternalworkloads.cilium.io 2024-10-26T13:12:33Z
ciliumidentities.cilium.io 2024-10-26T13:12:34Z
ciliuml2announcementpolicies.cilium.io 2024-10-26T13:12:34Z
ciliumloadbalancerippools.cilium.io 2024-10-26T13:12:33Z
ciliumnetworkpolicies.cilium.io 2024-10-26T13:12:34Z
ciliumnodeconfigs.cilium.io 2024-10-26T13:12:33Z
ciliumnodes.cilium.io 2024-10-26T13:12:33Z
ciliumpodippools.cilium.io 2024-10-26T13:12:33Z
(⎈|ciliumLab:N/A) root@k8s-s:~# k get ciliumnodes
NAME CILIUMINTERNALIP INTERNALIP AGE
k8s-s 172.16.0.109 192.168.10.10 74m
k8s-w1 172.16.2.3 192.168.10.101 73m
k8s-w2 172.16.1.78 192.168.10.102 73m
(⎈|ciliumLab:N/A) root@k8s-s:~# k get ciliumendpoints -A
NAMESPACE NAME SECURITY IDENTITY ENDPOINT STATE IPV4 IPV6
kube-system coredns-55cb58b774-7ltn5 50969 ready 172.16.1.93
kube-system coredns-55cb58b774-frd77 50969 ready 172.16.1.239
kube-system hubble-relay-88f7f89d4-xf7lh 12483 ready 172.16.2.67
kube-system hubble-ui-59bb4cb67b-m7m2s 3336 ready 172.16.2.225
설치 시 사용했던 config와 그 외 설정 값 확인
⎈|ciliumLab:N/A) root@k8s-s:~# k get cm -n kube-system cilium-config -o json | jq
{
"apiVersion": "v1",
"data": {
"agent-not-ready-taint-key": "node.cilium.io/agent-not-ready",
"arping-refresh-period": "30s",
"auto-direct-node-routes": "true",
"bpf-events-drop-enabled": "true",
"bpf-events-policy-verdict-enabled": "true",
"bpf-events-trace-enabled": "true",
"bpf-lb-acceleration": "disabled",
"bpf-lb-external-clusterip": "false",
"bpf-lb-map-max": "65536",
"bpf-lb-sock": "false",
"bpf-lb-sock-terminate-pod-connections": "false",
"bpf-map-dynamic-size-ratio": "0.0025",
"bpf-policy-map-max": "16384",
"bpf-root": "/sys/fs/bpf",
"cgroup-root": "/run/cilium/cgroupv2",
"cilium-endpoint-gc-interval": "5m0s",
"cluster-id": "0",
"cluster-name": "default",
"clustermesh-enable-endpoint-sync": "false",
"clustermesh-enable-mcs-api": "false",
"cni-exclusive": "true",
"cni-log-file": "/var/run/cilium/cilium-cni.log",
"controller-group-metrics": "write-cni-file sync-host-ips sync-lb-maps-with-k8s-services",
"custom-cni-conf": "false",
"datapath-mode": "veth",
"debug": "true",
"debug-verbose": "",
"direct-routing-skip-unreachable": "false",
"dnsproxy-enable-transparent-mode": "true",
"dnsproxy-socket-linger-timeout": "10",
"egress-gateway-reconciliation-trigger-interval": "1s",
"enable-auto-protect-node-port-range": "true",
"enable-bpf-clock-probe": "false",
"enable-bpf-masquerade": "true",
"enable-endpoint-health-checking": "true",
"enable-endpoint-routes": "true",
"enable-health-check-loadbalancer-ip": "false",
"enable-health-check-nodeport": "true",
"enable-health-checking": "true",
"enable-hubble": "true",
"enable-hubble-open-metrics": "true",
"enable-ipv4": "true",
"enable-ipv4-big-tcp": "false",
"enable-ipv4-masquerade": "true",
"enable-ipv6": "false",
"enable-ipv6-big-tcp": "false",
"enable-ipv6-masquerade": "true",
"enable-k8s-networkpolicy": "true",
"enable-k8s-terminating-endpoint": "true",
"enable-l2-neigh-discovery": "true",
"enable-l7-proxy": "true",
"enable-local-redirect-policy": "false",
"enable-masquerade-to-route-source": "false",
"enable-metrics": "true",
"enable-node-selector-labels": "false",
"enable-policy": "default",
"enable-runtime-device-detection": "true",
"enable-sctp": "false",
"enable-svc-source-range-check": "true",
"enable-tcx": "true",
"enable-vtep": "false",
"enable-well-known-identities": "false",
"enable-xt-socket-fallback": "true",
"envoy-base-id": "0",
"envoy-keep-cap-netbindservice": "false",
"external-envoy-proxy": "true",
"hubble-disable-tls": "false",
"hubble-export-file-max-backups": "5",
"hubble-export-file-max-size-mb": "10",
"hubble-listen-address": ":4244",
"hubble-metrics": "dns:query;ignoreAAAA drop tcp flow port-distribution icmp httpV2:exemplars=true;labelsContext=source_ip,source_namespace,source_workload,destination_ip,destination_namespace,destination_workload,traffic_direction",
"hubble-metrics-server": ":9965",
"hubble-metrics-server-enable-tls": "false",
"hubble-socket-path": "/var/run/cilium/hubble.sock",
"hubble-tls-cert-file": "/var/lib/cilium/tls/hubble/server.crt",
"hubble-tls-client-ca-files": "/var/lib/cilium/tls/hubble/client-ca.crt",
"hubble-tls-key-file": "/var/lib/cilium/tls/hubble/server.key",
"identity-allocation-mode": "crd",
"identity-gc-interval": "15m0s",
"identity-heartbeat-timeout": "30m0s",
"install-no-conntrack-iptables-rules": "true",
"ipam": "kubernetes",
"ipam-cilium-node-update-rate": "15s",
"ipv4-native-routing-cidr": "192.168.0.0/16",
"k8s-client-burst": "20",
"k8s-client-qps": "10",
"k8s-require-ipv4-pod-cidr": "true",
"k8s-require-ipv6-pod-cidr": "false",
"kube-proxy-replacement": "true",
"kube-proxy-replacement-healthz-bind-address": "",
"max-connected-clusters": "255",
"mesh-auth-enabled": "true",
"mesh-auth-gc-interval": "5m0s",
"mesh-auth-queue-size": "1024",
"mesh-auth-rotated-identities-queue-size": "1024",
"monitor-aggregation": "medium",
"monitor-aggregation-flags": "all",
"monitor-aggregation-interval": "5s",
"nat-map-stats-entries": "32",
"nat-map-stats-interval": "30s",
"node-port-bind-protection": "true",
"nodeport-addresses": "",
"nodes-gc-interval": "5m0s",
"operator-api-serve-addr": "127.0.0.1:9234",
"operator-prometheus-serve-addr": ":9963",
"policy-cidr-match-mode": "",
"preallocate-bpf-maps": "false",
"procfs": "/host/proc",
"prometheus-serve-addr": ":9962",
"proxy-connect-timeout": "2",
"proxy-idle-timeout-seconds": "60",
"proxy-max-connection-duration-seconds": "0",
"proxy-max-requests-per-connection": "0",
"proxy-xff-num-trusted-hops-egress": "0",
"proxy-xff-num-trusted-hops-ingress": "0",
"remove-cilium-node-taints": "true",
"routing-mode": "native",
"service-no-backend-response": "reject",
"set-cilium-is-up-condition": "true",
"set-cilium-node-taints": "true",
"synchronize-k8s-nodes": "true",
"tofqdns-dns-reject-response-code": "refused",
"tofqdns-enable-dns-compression": "true",
"tofqdns-endpoint-max-ip-per-hostname": "50",
"tofqdns-idle-connection-grace-period": "0s",
"tofqdns-max-deferred-connection-deletes": "10000",
"tofqdns-proxy-response-max-delay": "100ms",
"unmanaged-pod-watcher-interval": "15",
"vtep-cidr": "",
"vtep-endpoint": "",
"vtep-mac": "",
"vtep-mask": "",
"write-cni-conf-when-ready": "/host/etc/cni/net.d/05-cilium.conflist"
},
"kind": "ConfigMap",
"metadata": {
"annotations": {
"meta.helm.sh/release-name": "cilium",
"meta.helm.sh/release-namespace": "kube-system"
},
"creationTimestamp": "2024-10-26T14:23:44Z",
"labels": {
"app.kubernetes.io/managed-by": "Helm"
},
"name": "cilium-config",
"namespace": "kube-system",
"resourceVersion": "12182",
"uid": "a8eeaed3-32c5-4d7b-a1d4-b6389be7f0ef"
}
}
XDP 지원 확인
(⎈|ciliumLab:N/A) root@k8s-s:~# ethtool -i ens5
driver: ena
version: 6.8.0-1015-aws
firmware-version:
expansion-rom-version:
bus-info: 0000:00:05.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
raw table을 확인해보면 노드들에 대한 통신을 트래킹하지 않도록 설정한 정책들을 확인할 수 있습니다.
cilium 설치 시 사용한 installNoConntrackIptablesRules=true 설정의 영향이며, 기본 값은 False입니다.
주로 빠른 속도의 워크로드, 대용량 파일 전송, 낮은 레이턴시가 필요할 때 True를 사용하게 됩니다.
False인 경우 (기본값)
- 모든 패킷에 대해 connection tracking
- 상태 추적 (NEW, ESTABLISHED, RELATED 등)
- 메모리 및 CPU 리소스 사용
True인 경우
- 노드 간 통신에서 connection tracking 비활성화
- eBPF를 통한 직접 패킷 처리
- 리소스 사용 최적화
(⎈|ciliumLab:N/A) root@k8s-s:~# iptables -t raw -S | grep notrack
-A CILIUM_OUTPUT_raw -d 192.168.0.0/16 -m comment --comment "cilium: NOTRACK for pod traffic" -j CT --notrack
-A CILIUM_OUTPUT_raw -s 192.168.0.0/16 -m comment --comment "cilium: NOTRACK for pod traffic" -j CT --notrack
-A CILIUM_OUTPUT_raw -o lxc+ -m comment --comment "cilium: NOTRACK for proxy return traffic" -j CT --notrack
-A CILIUM_OUTPUT_raw -o cilium_host -m comment --comment "cilium: NOTRACK for proxy return traffic" -j CT --notrack
-A CILIUM_OUTPUT_raw -o lxc+ -m comment --comment "cilium: NOTRACK for L7 proxy upstream traffic" -j CT --notrack
-A CILIUM_OUTPUT_raw -o cilium_host -m comment --comment "cilium: NOTRACK for L7 proxy upstream traffic" -j CT --notrack
-A CILIUM_PRE_raw -d 192.168.0.0/16 -m comment --comment "cilium: NOTRACK for pod traffic" -j CT --notrack
-A CILIUM_PRE_raw -s 192.168.0.0/16 -m comment --comment "cilium: NOTRACK for pod traffic" -j CT --notrack
-A CILIUM_PRE_raw -m comment --comment "cilium: NOTRACK for proxy traffic" -j CT --notrack
Cilium CLI 설치
## $를 빼고 한번에 복사해서 명령어 실행해도 설치 가능
$ CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/main/stable.txt)
$ CLI_ARCH=amd64
$ if [ "$(uname -m)" = "aarch64" ]; then CLI_ARCH=arm64; fi
$ curl -L --fail --remote-name-all https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum}
$ sha256sum --check cilium-linux-${CLI_ARCH}.tar.gz.sha256sum
$ sudo tar xzvfC cilium-linux-${CLI_ARCH}.tar.gz /usr/local/bin
$ rm cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum}
설치 확인
config view 명령어를 통해 현재 설치된 cilium의 설정 값들을 확인해 볼 수 있습니다.
$ cilium config view
agent-not-ready-taint-key node.cilium.io/agent-not-ready
arping-refresh-period 30s
auto-direct-node-routes true
bpf-events-drop-enabled true
bpf-events-policy-verdict-enabled true
bpf-events-trace-enabled true
bpf-lb-acceleration disabled
bpf-lb-external-clusterip false
bpf-lb-map-max 65536
bpf-lb-sock false
bpf-lb-sock-terminate-pod-connections false
bpf-map-dynamic-size-ratio 0.0025
bpf-policy-map-max 16384
bpf-root /sys/fs/bpf
cgroup-root /run/cilium/cgroupv2
cilium-endpoint-gc-interval 5m0s
cluster-id 0
cluster-name default
clustermesh-enable-endpoint-sync false
clustermesh-enable-mcs-api false
cni-exclusive true
cni-log-file /var/run/cilium/cilium-cni.log
controller-group-metrics write-cni-file sync-host-ips sync-lb-maps-with-k8s-services
custom-cni-conf false
datapath-mode veth
debug true
debug-verbose
...
또 Cilium 데몬셋 pod 내부에서 cilium의 상태를 조회해볼 수 있습니다.
--verbose를 통해 controller의 상태라던지, Cluster의 상태나 cilium 각 모듈의 상태 같은 다양한 정보를 확인해 볼 수 있습니다.
## 두 명령어 중 어떤 것으로 해도 결과는 동일합니다.
$ export CILIUMPOD0=$(kubectl get -l k8s-app=cilium pods -n kube-system --field-selector spec.nodeName=k8s-s -o jsonpath='{.items[0].metadata.name}')
OR
$ export CILIUMPOD0=$(kubectl get -l k8s-app=cilium pods -n kube-system --filed-selector spec.nodeName=k8s-s -o name
## exec를 편하게 사용하도록 변수 지정
$ alias c0="kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium"
## cilium 상태 확인
$ c0 status --verbose
(⎈|ciliumLab:N/A) root@k8s-s:~# c0 status --verbose
KVStore: Ok Disabled
Kubernetes: Ok 1.30 (v1.30.6) [linux/amd64]
Kubernetes APIs: ["EndpointSliceOrEndpoint", "cilium/v2::CiliumClusterwideNetworkPolicy", "cilium/v2::CiliumEndpoint", "cilium/v2::CiliumNetworkPolicy", "cilium/v2::CiliumNode", "cilium/v2alpha1::CiliumCIDRGroup", "core/v1::Namespace", "core/v1::Pods", "core/v1::Service", "networking.k8s.io/v1::NetworkPolicy"]
KubeProxyReplacement: True [ens5 192.168.10.10 fe80::89:ffff:fe2a:25e9 (Direct Routing)]
Host firewall: Disabled
SRv6: Disabled
CNI Chaining: none
CNI Config file: successfully wrote CNI configuration file to /host/etc/cni/net.d/05-cilium.conflist
Cilium: Ok 1.16.3 (v1.16.3-f2217191)
NodeMonitor: Listening for events on 4 CPUs with 64x4096 of shared memory
Cilium health daemon: Ok
IPAM: IPv4: 2/254 allocated from 172.16.0.0/24,
Allocated addresses:
172.16.0.109 (router)
172.16.0.49 (health)
IPv4 BIG TCP: Disabled
IPv6 BIG TCP: Disabled
BandwidthManager: Disabled
Routing: Network: Native Host: BPF
Attach Mode: TCX
Device Mode: veth
Masquerading: BPF [ens5] 192.168.0.0/16 [IPv4: Enabled, IPv6: Disabled]
Clock Source for BPF: ktime
Controller Status: 21/21 healthy
Name Last success Last error Count Message
bpf-map-sync-cilium_lxc 7s ago never 0 no error
cilium-health-ep 15s ago never 0 no error
ct-map-pressure 23s ago never 0 no error
daemon-validate-config 13s ago never 0 no error
dns-garbage-collector-job 26s ago never 0 no error
endpoint-1859-regeneration-recovery never never 0 no error
endpoint-974-regeneration-recovery never never 0 no error
endpoint-gc 2m26s ago never 0 no error
ep-bpf-prog-watchdog 23s ago never 0 no error
ipcache-inject-labels 24s ago never 0 no error
k8s-heartbeat 25s ago never 0 no error
link-cache 8s ago never 0 no error
node-neighbor-link-updater 3s ago never 0 no error
resolve-identity-1859 2m22s ago never 0 no error
resolve-labels-/ 2h12m24s ago never 0 no error
restoring-ep-identity (974) 2h12m24s ago never 0 no error
sync-lb-maps-with-k8s-services 2h12m24s ago never 0 no error
sync-policymap-1859 12m16s ago never 0 no error
sync-policymap-974 12m20s ago never 0 no error
sync-utime 24s ago never 0 no error
write-cni-file 2h12m26s ago never 0 no error
Proxy Status: OK, ip 172.16.0.109, 0 redirects active on ports 10000-20000, Envoy: external
Global Identity Range: min 256, max 65535
Hubble: Ok Current/Max Flows: 4095/4095 (100.00%), Flows/s: 1.02 Metrics: Ok
KubeProxyReplacement Details:
Status: True
Socket LB: Enabled
Socket LB Tracing: Enabled
Socket LB Coverage: Full
Devices: ens5 192.168.10.10 fe80::89:ffff:fe2a:25e9 (Direct Routing)
Mode: SNAT
Backend Selection: Random
Session Affinity: Enabled
Graceful Termination: Enabled
NAT46/64 Support: Disabled
XDP Acceleration: Disabled
Services:
- ClusterIP: Enabled
- NodePort: Enabled (Range: 30000-32767)
- LoadBalancer: Enabled
- externalIPs: Enabled
- HostPort: Enabled
...
Agent 기반의 Masqerade를 사용하도록 설정 업데이트
$ helm upgrade cilium cilium/cilium --namespace kube-system --reuse-values --set ipMasqAgent.enabled=true
$ c0 status --verbose | grep Masquerading
Masquerading: BPF (ip-masq-agent) [ens5] 192.168.0.0/16 [IPv4: Enabled, IPv6: Disabled]
Cilium CLI 자주 사용하는 명령어
# cilium 파드 확인
kubectl get pod -n kube-system -l k8s-app=cilium -owide
# cilium 파드 재시작
kubectl -n kube-system rollout restart ds/cilium
혹은
kubectl delete pod -n kube-system -l k8s-app=cilium
# cilium 설정 정보 확인
cilium config view
# cilium 파드의 cilium 상태 확인
c0 status --verbose
# cilium 엔드포인트 확인
kubectl get ciliumendpoints -A
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium endpoint list
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium bpf endpoint list
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium map get cilium_lxc
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium ip list
# Manage the IPCache mappings for IP/CIDR <-> Identity
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium bpf ipcache list
# Service/NAT List 확인
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium service list
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium bpf lb list
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium bpf lb list --revnat
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium bpf nat list
# List all open BPF maps
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium map list
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium map list --verbose
# List contents of a policy BPF map : Dump all policy maps
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium bpf policy get --all
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium bpf policy get --all -n
# cilium monitor
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium monitor -v
kubectl exec -it $CILIUMPOD0 -n kube-system -c cilium-agent -- cilium monitor -v --type l7
Cilium Packet Flow
Hubble UI & CLI
Hubble은 통신 및 서비스와 네트워킹 인프라의 동작에 대한 심층적인 가시성을 완전히 투명한 방식으로 제공하는 관찰성을 제공
클라우드 네이티브 환경에서의 네트워크 모니터링과 트러블슈팅에 사용할 수 있고, eBPF 기반으로 모니터링하기 때문에 오버헤드를 최소화하며 동작합니다.
Hubble은 Prometheus, Grafana에 통합하여 모니터링도 가능합니다.
- Hubble 주요 기능
1. 네트워크 가시성
- L3/L4/L7 트래픽 모니터링
- 서비스 의존성 맵
- 네트워크 플로우 추적
2. 보안 관찰성
- 보안 이벤트 탐지
- 정책 위반 모니터링
- DNS 요청 추적
3. 성능 모니터링
- 레이턴시 측정
- 처리량 통계
- 에러율 모니터링
Hubble UI 접속
$ kubectl patch -n kube-system svc hubble-ui -p '{"spec": {"type": "NodePort"}}'
$ HubbleUiNodePort=$(kubectl get svc -n kube-system hubble-ui -o jsonpath={.spec.ports[0].nodePort})
$ echo -e "Hubble UI URL = http://$(curl -s ipinfo.io/ip):$HubbleUiNodePort"
Hubble CLI 설치
$ HUBBLE_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/hubble/master/stable.txt)
$ HUBBLE_ARCH=amd64
$ if [ "$(uname -m)" = "aarch64" ]; then HUBBLE_ARCH=arm64; fi
$ curl -L --fail --remote-name-all https://github.com/cilium/hubble/releases/download/$HUBBLE_VERSION/hubble-linux-${HUBBLE_ARCH}.tar.gz{,.sha256sum}
$ sha256sum --check hubble-linux-${HUBBLE_ARCH}.tar.gz.sha256sum
$ sudo tar xzvfC hubble-linux-${HUBBLE_ARCH}.tar.gz /usr/local/bin
$ rm hubble-linux-${HUBBLE_ARCH}.tar.gz{,.sha256sum}
Hubble API Access : Observe를 통해 Flow 쿼리 확인 가능
$ cilium hubble port-forward &
## CLI를 통해 API 상태 확인
$ hubble status
Healthcheck (via localhost:4245): Ok
Current/Max Flows: 10,593/12,285 (86.23%)
Flows/s: 39.92
## Flow 쿼리를 확인합니다.
$ hubble observe
'Cloud > Kubernetes' 카테고리의 다른 글
[KANS] AWS EKS : VPC CNI (4) | 2024.11.03 |
---|---|
[KANS] Cilium + eBPF (2) (2) | 2024.10.27 |
[KANS] Istio - Traffic Management (0) | 2024.10.20 |
[KANS] Istio example (bookinfo) (1) | 2024.10.20 |
[KANS] istio install + expose (0) | 2024.10.20 |