
6주차 실습 환경은 Cilium의 고급 보안 기능과 Service Mesh 기능을 다루기 위해 멀티 티어 애플리케이션과 다양한 보안 시나리오를 포함한 복합적인 환경으로 구성됩니다.
환경 구성의 핵심 특징:
멀티 티어 애플리케이션 아키텍처:
네트워크 보안 존 분리:
보안 시나리오 테스트:
핵심 구성 요소:
Vagrant를 통한 확장 보안 환경 배포:
# 실습 환경 배포
mkdir cilium-security-lab && cd cilium-security-lab
curl -O https://raw.githubusercontent.com/gasida/vagrant-lab/refs/heads/main/cilium-study/6w/Vagrantfile
# 추가 보안 도구 설치 스크립트 다운로드
curl -O https://raw.githubusercontent.com/gasida/vagrant-lab/refs/heads/main/cilium-study/6w/security-tools.sh
curl -O https://raw.githubusercontent.com/gasida/vagrant-lab/refs/heads/main/cilium-study/6w/demo-apps.sh
chmod +x *.sh
# 보안 강화 환경 배포 (약 25-30분 소요)
vagrant up
# 추가 보안 도구 설치
./security-tools.sh
기본 보안 상태 확인:
# Cilium 보안 기능 상태 확인
cilium status | grep -i security
cilium config view | grep -E 'policy|encryption|identity'
# 네트워크 정책 엔진 상태
kubectl get ciliumpolicy,ciliumnetworkpolicy,ciliumclusterwidenetworkpolicy -A
# Identity 시스템 확인
kubectl exec -n kube-system ds/cilium -c cilium-agent -- cilium-dbg identity list
kubectl exec -n kube-system ds/cilium -c cilium-agent -- cilium-dbg endpoint list

Cilium의 네트워크 보안은 기존의 IP 주소 기반 접근 방식을 벗어나 Identity 기반 보안 모델을 채택합니다. 이는 클라우드 네이티브 환경의 동적 특성에 최적화된 혁신적인 접근 방식입니다.
Identity 기반 보안의 핵심 개념:
1. Security Identity 자동 할당
2. Label Selector 기반 정책
# 예시: app=backend 라벨을 가진 모든 Pod가 동일한 Security Identity 공유
endpointSelector:
matchLabels:
app: backend
version: v1
3. 동적 정책 업데이트
4. 성능 최적화
기본 L3/L4 정책 구조:
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "backend-policy"
spec:
endpointSelector:
matchLabels:
app: backend
ingress:
- fromEndpoints:
- matchLabels:
app: frontend
toPorts:
- ports:
- port: "8080"
protocol: TCP
egress:
- toEndpoints:
- matchLabels:
app: database
toPorts:
- ports:
- port: "5432"
protocol: TCP
고급 L3/L4 정책 기능:
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "advanced-l3l4-policy"
spec:
endpointSelector:
matchLabels:
tier: backend
ingress:
# CIDR 기반 접근 제어
- fromCIDR:
- "10.0.0.0/8"
- "192.168.0.0/16"
# Entity 기반 접근 제어
- fromEntities:
- "cluster"
- "host"
# 서비스 기반 접근 제어
- fromServices:
- name: "external-api"
namespace: "external"
egress:
# DNS 기반 FQDN 정책
- toFQDNs:
- matchName: "api.external-service.com"
- matchPattern: "*.safe-domain.com"
# 포트 범위 정책
- toPorts:
- ports:
- port: "3000"
endPort: "3010"
protocol: TCP
HTTP 프로토콜 보안:
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "api-security-policy"
spec:
endpointSelector:
matchLabels:
app: api-server
ingress:
- fromEndpoints:
- matchLabels:
app: web-frontend
toPorts:
- ports:
- port: "8080"
protocol: TCP
rules:
http:
# HTTP 메서드 제한
- method: "GET"
path: "/api/v1/users"
- method: "POST"
path: "/api/v1/users"
headers:
- "Content-Type: application/json"
- "Authorization: Bearer .*"
# 특정 경로 차단
- method: "GET"
path: "/api/v1/admin/.*"
action: "DENY"
gRPC 프로토콜 보안:
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "grpc-service-policy"
spec:
endpointSelector:
matchLabels:
app: grpc-service
ingress:
- fromEndpoints:
- matchLabels:
app: grpc-client
toPorts:
- ports:
- port: "9090"
protocol: TCP
rules:
grpc:
# gRPC 서비스별 접근 제어
- service: "user.UserService"
method: "GetUser"
- service: "user.UserService"
method: "CreateUser"
# 관리자 서비스 차단
- service: "admin.*"
action: "DENY"
Kafka 프로토콜 보안:
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "kafka-security-policy"
spec:
endpointSelector:
matchLabels:
app: kafka-consumer
egress:
- toEndpoints:
- matchLabels:
app: kafka-broker
toPorts:
- ports:
- port: "9092"
protocol: TCP
rules:
kafka:
# 특정 토픽만 접근 허용
- apiKey: "produce"
topic: "user-events"
- apiKey: "consume"
topic: "user-events"
# 관리자 토픽 차단
- apiKey: ".*"
topic: "admin-.*"
action: "DENY"
멀티 티어 애플리케이션 배포:
# 네임스페이스 생성
kubectl create namespace frontend
kubectl create namespace backend
kubectl create namespace database
kubectl create namespace external
# Frontend 애플리케이션 배포
cat << EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
namespace: frontend
spec:
replicas: 2
selector:
matchLabels:
app: frontend
tier: web
template:
metadata:
labels:
app: frontend
tier: web
version: v1
spec:
containers:
- name: frontend
image: nginx:alpine
ports:
- containerPort: 80
env:
- name: BACKEND_URL
value: "http://backend.backend.svc.cluster.local:8080"
---
apiVersion: v1
kind: Service
metadata:
name: frontend
namespace: frontend
spec:
selector:
app: frontend
ports:
- port: 80
targetPort: 80
type: ClusterIP
EOF
# Backend API 서버 배포
cat << EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
namespace: backend
spec:
replicas: 2
selector:
matchLabels:
app: backend
tier: api
template:
metadata:
labels:
app: backend
tier: api
version: v1
spec:
containers:
- name: backend
image: httpd:alpine
ports:
- containerPort: 8080
env:
- name: DATABASE_URL
value: "postgresql://database.database.svc.cluster.local:5432/appdb"
---
apiVersion: v1
kind: Service
metadata:
name: backend
namespace: backend
spec:
selector:
app: backend
ports:
- port: 8080
targetPort: 8080
type: ClusterIP
EOF
# Database 배포
cat << EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: database
namespace: database
spec:
replicas: 1
selector:
matchLabels:
app: database
tier: data
template:
metadata:
labels:
app: database
tier: data
version: v1
spec:
containers:
- name: database
image: postgres:13-alpine
ports:
- containerPort: 5432
env:
- name: POSTGRES_DB
value: "appdb"
- name: POSTGRES_USER
value: "appuser"
- name: POSTGRES_PASSWORD
value: "apppass"
---
apiVersion: v1
kind: Service
metadata:
name: database
namespace: database
spec:
selector:
app: database
ports:
- port: 5432
targetPort: 5432
type: ClusterIP
EOF
# 테스트 클라이언트 배포
cat << EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: test-client
namespace: frontend
labels:
app: test-client
spec:
containers:
- name: client
image: nicolaka/netshoot
command: ["tail"]
args: ["-f", "/dev/null"]
EOF
# 현재 연결성 확인 (정책 적용 전)
kubectl exec -it test-client -n frontend -- curl -s backend.backend.svc.cluster.local:8080
kubectl exec -it test-client -n frontend -- curl -s database.database.svc.cluster.local:5432
# Hubble로 트래픽 플로우 관찰
hubble observe -f --namespace frontend,backend,database
# Identity 정보 확인
kubectl exec -n kube-system ds/cilium -c cilium-agent -- cilium-dbg identity list
kubectl exec -n kube-system ds/cilium -c cilium-agent -- cilium-dbg endpoint list
1단계: 기본 거부 정책 (Default Deny)
# 모든 네임스페이스에 기본 거부 정책 적용
cat << EOF | kubectl apply -f -
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "default-deny-all"
namespace: frontend
spec:
endpointSelector: {}
ingress: []
egress: []
---
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "default-deny-all"
namespace: backend
spec:
endpointSelector: {}
ingress: []
egress: []
---
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "default-deny-all"
namespace: database
spec:
endpointSelector: {}
ingress: []
egress: []
EOF
# 연결성 테스트 (모든 통신 차단 확인)
kubectl exec -it test-client -n frontend -- curl -s --connect-timeout 5 backend.backend.svc.cluster.local:8080
# Expected: Connection timeout
# Hubble로 차단된 트래픽 확인
hubble observe -f --verdict DENIED
2단계: 선택적 통신 허용 정책
# Frontend → Backend 통신 허용
cat << EOF | kubectl apply -f -
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "frontend-to-backend"
namespace: backend
spec:
endpointSelector:
matchLabels:
app: backend
ingress:
- fromEndpoints:
- matchLabels:
app: frontend
namespaceSelector:
matchLabels:
name: frontend
toPorts:
- ports:
- port: "8080"
protocol: TCP
EOF
# Backend → Database 통신 허용
cat << EOF | kubectl apply -f -
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "backend-to-database"
namespace: database
spec:
endpointSelector:
matchLabels:
app: database
ingress:
- fromEndpoints:
- matchLabels:
app: backend
namespaceSelector:
matchLabels:
name: backend
toPorts:
- ports:
- port: "5432"
protocol: TCP
EOF
# DNS 해결을 위한 CoreDNS 통신 허용
cat << EOF | kubectl apply -f -
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "allow-dns"
namespace: frontend
spec:
endpointSelector:
matchLabels:
app: frontend
egress:
- toEndpoints:
- matchLabels:
k8s-app: kube-dns
namespaceSelector:
matchLabels:
name: kube-system
toPorts:
- ports:
- port: "53"
protocol: UDP
- port: "53"
protocol: TCP
---
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "allow-dns"
namespace: backend
spec:
endpointSelector:
matchLabels:
app: backend
egress:
- toEndpoints:
- matchLabels:
k8s-app: kube-dns
namespaceSelector:
matchLabels:
name: kube-system
toPorts:
- ports:
- port: "53"
protocol: UDP
- port: "53"
protocol: TCP
EOF
# 연결성 테스트
kubectl exec -it test-client -n frontend -- curl -s backend.backend.svc.cluster.local:8080
# Expected: Success
# 허용되지 않은 연결 테스트
kubectl exec -it test-client -n frontend -- curl -s --connect-timeout 5 database.database.svc.cluster.local:5432
# Expected: Connection timeout (정책에 의해 차단)
HTTP 애플리케이션 배포:
# HTTP API 서버 배포
cat << EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: http-api
namespace: backend
spec:
replicas: 2
selector:
matchLabels:
app: http-api
tier: api
template:
metadata:
labels:
app: http-api
tier: api
spec:
containers:
- name: api
image: traefik/whoami
ports:
- containerPort: 80
env:
- name: WHOAMI_PORT_NUMBER
value: "80"
---
apiVersion: v1
kind: Service
metadata:
name: http-api
namespace: backend
spec:
selector:
app: http-api
ports:
- port: 80
targetPort: 80
type: ClusterIP
EOF
L7 HTTP 보안 정책 적용:
cat << EOF | kubectl apply -f -
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "http-l7-policy"
namespace: backend
spec:
endpointSelector:
matchLabels:
app: http-api
ingress:
- fromEndpoints:
- matchLabels:
app: frontend
namespaceSelector:
matchLabels:
name: frontend
toPorts:
- ports:
- port: "80"
protocol: TCP
rules:
http:
# GET 요청만 허용
- method: "GET"
path: "/"
# 특정 헤더가 있는 요청만 허용
- method: "GET"
path: "/api/.*"
headers:
- "X-API-Version: v1"
# Admin 경로 차단
- method: ".*"
path: "/admin/.*"
action: "DENY"
EOF
# L7 정책 테스트
kubectl exec -it test-client -n frontend -- curl -s http-api.backend.svc.cluster.local
# Expected: Success (GET / 허용)
kubectl exec -it test-client -n frontend -- curl -s -X POST http-api.backend.svc.cluster.local
# Expected: Denied (POST 차단)
kubectl exec -it test-client -n frontend -- curl -s -H "X-API-Version: v1" http-api.backend.svc.cluster.local/api/users
# Expected: Success (헤더 조건 만족)
kubectl exec -it test-client -n frontend -- curl -s http-api.backend.svc.cluster.local/admin/config
# Expected: Denied (admin 경로 차단)
# Hubble로 L7 트래픽 분석
hubble observe -f --protocol http --namespace backend
hubble observe -f --verdict DENIED --namespace backend
# 외부 API 통신을 위한 FQDN 정책
cat << EOF | kubectl apply -f -
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "external-api-policy"
namespace: backend
spec:
endpointSelector:
matchLabels:
app: backend
egress:
# 신뢰할 수 있는 외부 API만 허용
- toFQDNs:
- matchName: "api.github.com"
- matchName: "httpbin.org"
- matchPattern: "*.googleapis.com"
# DNS 해결 허용
- toEndpoints:
- matchLabels:
k8s-app: kube-dns
namespaceSelector:
matchLabels:
name: kube-system
toPorts:
- ports:
- port: "53"
protocol: UDP
- port: "53"
protocol: TCP
# HTTPS 트래픽 허용 (443 포트)
- toPorts:
- ports:
- port: "443"
protocol: TCP
EOF
# FQDN 정책 테스트
kubectl exec -it test-client -n frontend -- curl -s https://httpbin.org/get
# Expected: Success (허용된 FQDN)
kubectl exec -it test-client -n frontend -- curl -s --connect-timeout 5 https://malicious-site.com
# Expected: Timeout (차단된 FQDN)
# DNS 쿼리 및 FQDN 매핑 확인
kubectl exec -n kube-system ds/cilium -c cilium-agent -- cilium-dbg fqdn cache list

WireGuard의 혁신적 특징:
1. 현대적 암호화
2. 단순한 구현
3. 고성능
4. 투명한 암호화
WireGuard vs IPSec 비교표:
| 특징 | WireGuard | IPSec |
|---|---|---|
| 코드 크기 | ~4,000 라인 | ~400,000+ 라인 |
| 설정 복잡도 | 간단 | 복잡 |
| 암호화 알고리즘 | 현대적 (ChaCha20) | 레거시 (AES) |
| 성능 | 높음 | 보통 |
| 디버깅 | 쉬움 | 어려움 |
| 키 교환 | Curve25519 | RSA/DH |
Cilium WireGuard 구현의 특징:
1. 자동 키 관리
2. 투명한 암호화
3. 성능 최적화
# WireGuard 모듈 확인
lsmod | grep wireguard
modinfo wireguard
# 모든 노드에서 WireGuard 모듈 로드
modprobe wireguard
sshpass -p 'vagrant' ssh vagrant@k8s-w1 sudo modprobe wireguard
sshpass -p 'vagrant' ssh vagrant@k8s-w0 sudo modprobe wireguard
# Cilium에서 WireGuard 암호화 활성화
helm upgrade cilium cilium/cilium \
--namespace kube-system \
--reuse-values \
--set encryption.enabled=true \
--set encryption.type=wireguard
# Cilium Agent 재시작
kubectl rollout restart -n kube-system ds/cilium
# 암호화 상태 확인
cilium status | grep -i encryption
# Expected: Encryption: Wireguard [NodeEncryption: Disabled, cilium_wg0 (Pubkey: <public-key>, Port: 51871, Peers: 2)]
# WireGuard 인터페이스 확인
ip -c addr show cilium_wg0
ip -c link show cilium_wg0
# WireGuard 설정 확인
wg show cilium_wg0
# 모든 노드의 WireGuard 상태 확인
for node in w1 w0; do
echo "=== Node: k8s-$node ==="
sshpass -p 'vagrant' ssh vagrant@k8s-$node sudo wg show cilium_wg0
echo
done
# Cilium WireGuard 키 정보
kubectl get secret -n kube-system cilium-wireguard-keys -o yaml | yq
kubectl exec -n kube-system ds/cilium -c cilium-agent -- cilium-dbg wg
# 예상 출력:
# interface: cilium_wg0
# public key: <base64-public-key>
# private key: (hidden)
# listening port: 51871
#
# peer: <peer-public-key>
# endpoint: 192.168.10.101:51871
# allowed ips: 172.20.1.0/24
# latest handshake: 2 minutes, 15 seconds ago
# transfer: 1.25 MiB received, 1.18 MiB sent
# 테스트 Pod 간 통신
kubectl exec -it test-client -n frontend -- ping -c 3 backend.backend.svc.cluster.local
# 패킷 캡처로 암호화 확인
# 터미널 1: WireGuard 트래픽 모니터링
tcpdump -i cilium_wg0 -nn
tcpdump -i eth1 udp port 51871 -nn
# 터미널 2: 암호화되지 않은 인터페이스에서 확인
tcpdump -i eth1 icmp -nn
# 암호화 후에는 ICMP 패킷이 보이지 않고 WireGuard UDP 패킷만 보임
# Hubble로 암호화된 플로우 확인
hubble observe -f --namespace frontend,backend
# WireGuard 통계 정보
wg show all transfer
cat /proc/net/dev | grep cilium_wg0

# iperf3를 통한 암호화 성능 측정
# 서버 Pod 배포
cat << EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: iperf3-server
namespace: backend
labels:
app: iperf3-server
spec:
containers:
- name: iperf3
image: networkstatic/iperf3
args: ["-s"]
ports:
- containerPort: 5201
EOF
# 클라이언트에서 성능 테스트
kubectl exec -it test-client -n frontend -- iperf3 -c iperf3-server.backend.svc.cluster.local -t 30
# 암호화 비활성화 후 성능 비교
helm upgrade cilium cilium/cilium \
--namespace kube-system \
--reuse-values \
--set encryption.enabled=false
kubectl rollout restart -n kube-system ds/cilium
# 다시 성능 테스트하여 오버헤드 측정
kubectl exec -it test-client -n frontend -- iperf3 -c iperf3-server.backend.svc.cluster.local -t 30
# 결과 비교 (일반적으로 5-10% 성능 저하)
# 노드 간 암호화 활성화 (호스트 네트워크 포함)
helm upgrade cilium cilium/cilium \
--namespace kube-system \
--reuse-values \
--set encryption.enabled=true \
--set encryption.type=wireguard \
--set encryption.nodeEncryption=true
# 호스트 네트워크 암호화 확인
kubectl exec -n kube-system ds/cilium -c cilium-agent -- cilium status | grep -i "Node Encryption"
# Expected: Node Encryption: Enabled
# 호스트 간 통신 암호화 테스트
ping -c 3 192.168.10.101 # k8s-w1로 ping
sshpass -p 'vagrant' ssh vagrant@k8s-w1 ping -c 3 192.168.20.100 # k8s-w0로 ping
# 호스트 트래픽 모니터링
tcpdump -i cilium_wg0 -nn host 192.168.10.101

전통적 Service Mesh (Istio, Linkerd)의 한계:
1. 사이드카 오버헤드
2. 운영 복잡성
Cilium Service Mesh의 혁신:
1. eBPF 기반 구현
2. 투명한 서비스 메시
1. Ingress 트래픽 관리
2. Service-to-Service 통신
3. 관찰 가능성
# Cilium Ingress Controller 활성화
helm upgrade cilium cilium/cilium \
--namespace kube-system \
--reuse-values \
--set ingressController.enabled=true \
--set ingressController.service.type=NodePort \
--set ingressController.service.nodePorts.http=30080 \
--set ingressController.service.nodePorts.https=30443
# Ingress Controller 상태 확인
kubectl get pods -n kube-system -l app.kubernetes.io/name=cilium-ingress
kubectl get svc -n kube-system cilium-ingress
# Ingress Class 확인
kubectl get ingressclass
# Expected: cilium ingressclass 생성됨
# 백엔드 서비스를 위한 Ingress 생성
cat << EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: basic-ingress
namespace: backend
annotations:
ingress.cilium.io/service-type: "ClusterIP"
spec:
ingressClassName: cilium
rules:
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: http-api
port:
number: 80
- path: /v2
pathType: Prefix
backend:
service:
name: backend
port:
number: 8080
EOF
# Ingress 상태 확인
kubectl get ingress -n backend
kubectl describe ingress basic-ingress -n backend
# 외부에서 접근 테스트
curl -H "Host: api.example.com" http://192.168.10.100:30080/
curl -H "Host: api.example.com" http://192.168.10.100:30080/v2
# TLS 인증서 생성
openssl req -x509 -newkey rsa:4096 -keyout tls.key -out tls.crt -days 365 -nodes \
-subj "/CN=api.example.com/O=Example Org"
# TLS Secret 생성
kubectl create secret tls api-tls-secret --cert=tls.crt --key=tls.key -n backend
# HTTPS Ingress 설정
cat << EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tls-ingress
namespace: backend
annotations:
ingress.cilium.io/service-type: "ClusterIP"
spec:
ingressClassName: cilium
tls:
- hosts:
- api.example.com
secretName: api-tls-secret
rules:
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: http-api
port:
number: 80
EOF
# HTTPS 접근 테스트
curl -k -H "Host: api.example.com" https://192.168.10.100:30443/


Gateway API는 Ingress의 한계를 극복하기 위해 설계된 차세대 트래픽 관리 API입니다:
Gateway API의 주요 특징:
# Gateway API CRD 설치
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.0.0/standard-install.yaml
# Cilium Gateway API 지원 활성화
helm upgrade cilium cilium/cilium \
--namespace kube-system \
--reuse-values \
--set gatewayAPI.enabled=true
# GatewayClass 생성
cat << EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: cilium
spec:
controllerName: io.cilium/gateway-controller
EOF
# Gateway 생성
cat << EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: api-gateway
namespace: backend
spec:
gatewayClassName: cilium
listeners:
- name: http
port: 80
protocol: HTTP
allowedRoutes:
namespaces:
from: Same
- name: https
port: 443
protocol: HTTPS
allowedRoutes:
namespaces:
from: Same
tls:
certificateRefs:
- name: api-tls-secret
EOF
# HTTPRoute 생성
cat << EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: api-route
namespace: backend
spec:
parentRefs:
- name: api-gateway
hostnames:
- api.example.com
rules:
- matches:
- path:
type: PathPrefix
value: /api/v1
backendRefs:
- name: http-api
port: 80
- matches:
- path:
type: PathPrefix
value: /api/v2
backendRefs:
- name: backend
port: 8080
EOF
# Gateway 상태 확인
kubectl get gateway,httproute -n backend
kubectl describe gateway api-gateway -n backend

# 헤더 기반 라우팅 HTTPRoute
cat << EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: header-based-route
namespace: backend
spec:
parentRefs:
- name: api-gateway
rules:
# API 버전별 라우팅
- matches:
- headers:
- name: "X-API-Version"
value: "v1"
backendRefs:
- name: http-api
port: 80
- matches:
- headers:
- name: "X-API-Version"
value: "v2"
backendRefs:
- name: backend
port: 8080
# 기본 라우팅
- backendRefs:
- name: http-api
port: 80
EOF
# 헤더 기반 라우팅 테스트
curl -H "Host: api.example.com" -H "X-API-Version: v1" http://192.168.10.100:30080/
curl -H "Host: api.example.com" -H "X-API-Version: v2" http://192.168.10.100:30080/
# 카나리 배포를 위한 트래픽 분할
cat << EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: canary-route
namespace: backend
spec:
parentRefs:
- name: api-gateway
rules:
- matches:
- path:
type: PathPrefix
value: /canary
backendRefs:
# 90% 트래픽을 stable 버전으로
- name: http-api
port: 80
weight: 90
# 10% 트래픽을 canary 버전으로
- name: backend
port: 8080
weight: 10
EOF
# 트래픽 분할 테스트
for i in {1..100}; do
curl -s -H "Host: api.example.com" http://192.168.10.100:30080/canary | grep -o "backend\|http-api"
done | sort | uniq -c
# Expected: 약 90:10 비율로 분산
# Rate Limiting 정책 적용
cat << EOF | kubectl apply -f -
apiVersion: cilium.io/v2
kind: CiliumEnvoyConfig
metadata:
name: rate-limit-config
namespace: backend
spec:
services:
- name: http-api
namespace: backend
resources:
- "@type": type.googleapis.com/envoy.config.listener.v3.Listener
name: envoy-prometheus-metrics-listener
address:
socket_address:
address: "0.0.0.0"
port_value: 9964
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match:
prefix: "/"
route:
cluster: backend
rate_limits:
- actions:
- request_headers:
header_name: "x-client-id"
descriptor_key: "client_id"
http_filters:
- name: envoy.filters.http.local_ratelimit
typed_config:
"@type": type.googleapis.com/udpa.type.v1.TypedStruct
type_url: type.googleapis.com/envoy.extensions.filters.http.local_ratelimit.v3.LocalRateLimit
value:
stat_prefix: http_local_rate_limiter
token_bucket:
max_tokens: 10
tokens_per_fill: 10
fill_interval: 60s
filter_enabled:
runtime_key: test_enabled
default_value:
numerator: 100
denominator: HUNDRED
filter_enforced:
runtime_key: test_enforced
default_value:
numerator: 100
denominator: HUNDRED
- name: envoy.filters.http.router
EOF
# Rate Limiting 테스트
for i in {1..20}; do
curl -s -o /dev/null -w "%{http_code}\n" -H "Host: api.example.com" http://192.168.10.100:30080/
done
# Expected: 처음 10개는 200, 나머지는 429 (Too Many Requests)

# 보안 관련 플로우 모니터링
hubble observe -f --verdict DENIED
hubble observe -f --type policy-verdict
hubble observe -f --type drop
# L7 보안 이벤트 모니터링
hubble observe -f --protocol http --verdict DENIED
hubble observe -f --namespace backend --type l7
# 실시간 보안 대시보드
watch "hubble observe --last 100 --verdict DENIED | tail -20"
# Cilium 보안 메트릭 확인
kubectl exec -n kube-system ds/cilium -c cilium-agent -- curl -s localhost:9962/metrics | grep -E "policy|drop|denied"
# 주요 보안 메트릭:
# cilium_policy_verdict_total{verdict="DENIED"}
# cilium_drop_count_total
# cilium_drops_total{reason="Policy denied"}
# cilium_policy_l7_denied_total
# 보안 알림 규칙 생성
cat << EOF | kubectl apply -f -
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: cilium-security-alerts
namespace: kube-system
spec:
groups:
- name: cilium-security
rules:
- alert: CiliumPolicyViolationHigh
expr: increase(cilium_policy_verdict_total{verdict="DENIED"}[5m]) > 10
for: 2m
labels:
severity: warning
annotations:
summary: "High number of policy violations detected"
description: "{{ $value }} policy violations in the last 5 minutes"
- alert: CiliumPacketDropHigh
expr: increase(cilium_drop_count_total[5m]) > 100
for: 2m
labels:
severity: critical
annotations:
summary: "High packet drop rate detected"
description: "{{ $value }} packets dropped in the last 5 minutes"
- alert: CiliumL7PolicyViolation
expr: increase(cilium_policy_l7_denied_total[5m]) > 5
for: 1m
labels:
severity: warning
annotations:
summary: "L7 policy violations detected"
description: "{{ $value }} L7 policy violations in the last 5 minutes"
EOF
# Grafana 보안 대시보드 Import
# Dashboard ID: Cilium Security Dashboard (커스텀 제작)
# 주요 보안 패널:
# - Policy Violation Rate
# - Packet Drop Rate
# - L7 Security Events
# - FQDN Policy Violations
# - Top Denied Sources/Destinations
# - Security Identity Changes
보안 관련 에피소드:
Service Mesh 관련 에피소드:
보안 정책 문서:
암호화 문서:
Service Mesh 문서:
단계적 Zero Trust 도입 전략:
1단계: 가시성 확보
# 현재 트래픽 패턴 분석
hubble observe --last 10000 > traffic-analysis.log
cat traffic-analysis.log | grep -E "ALLOWED|DENIED" | sort | uniq -c
# 서비스 간 의존성 맵 생성
hubble observe --last 10000 --type trace | \
jq -r '"\(.source.namespace)/\(.source.labels.app) -> \(.destination.namespace)/\(.destination.labels.app)"' | \
sort | uniq > service-dependencies.txt
2단계: 점진적 정책 적용
# 관찰 모드 정책 (모니터링만, 차단 안 함)
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "observe-only-policy"
spec:
endpointSelector:
matchLabels:
app: production-app
ingress:
- fromEndpoints:
- matchLabels:
app: authorized-client
policyEnforcement: false # 관찰 모드
3단계: 강제 적용
# 점진적으로 정책 강제 적용
kubectl patch ciliumnetworkpolicy observe-only-policy \
--type='merge' -p='{"spec":{"policyEnforcement":true}}'
레이블 설계 전략:
# 일관된 레이블 체계
metadata:
labels:
app: "user-service" # 애플리케이션 이름
version: "v1.2.3" # 버전
tier: "backend" # 계층 (frontend/backend/database)
team: "platform" # 팀
environment: "production" # 환경 (dev/staging/production)
security-zone: "restricted" # 보안 존 (public/internal/restricted)
네임스페이스 분리 전략:
# 환경별 네임스페이스
kubectl create namespace production
kubectl create namespace staging
kubectl create namespace development
# 팀별 네임스페이스
kubectl create namespace team-platform
kubectl create namespace team-data
kubectl create namespace team-mobile
# 보안 존별 네임스페이스
kubectl create namespace public-zone
kubectl create namespace internal-zone
kubectl create namespace restricted-zone
WireGuard 권장 시나리오:
IPSec 권장 시나리오:
하드웨어 가속 활용:
# Intel AES-NI 지원 확인
grep -m1 -o aes /proc/cpuinfo
lscpu | grep AES
# WireGuard 성능 최적화 설정
helm upgrade cilium cilium/cilium \
--namespace kube-system \
--reuse-values \
--set encryption.enabled=true \
--set encryption.type=wireguard \
--set encryption.wireguard.userspaceFallback=false
암호화 오버헤드 최소화:
# 점보 프레임 활용 (가능한 경우)
ip link set dev eth1 mtu 9000
# CPU 친화성 설정
kubectl patch daemonset cilium -n kube-system -p='
{
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "cilium-agent",
"resources": {
"requests": {
"cpu": "500m",
"memory": "512Mi"
},
"limits": {
"cpu": "2000m",
"memory": "2Gi"
}
}
}
]
}
}
}
}'
1단계: Ingress Controller 도입
# 기존 NGINX Ingress Controller 대체
helm upgrade cilium cilium/cilium \
--namespace kube-system \
--reuse-values \
--set ingressController.enabled=true
# 점진적 트래픽 이전
kubectl patch ingress app-ingress -p='
{
"metadata": {
"annotations": {
"kubernetes.io/ingress.class": "cilium"
}
}
}'
2단계: L7 정책 적용
# HTTP 기반 세밀한 접근 제어
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
name: "api-rate-limiting"
spec:
endpointSelector:
matchLabels:
app: api-server
ingress:
- fromEndpoints:
- matchLabels:
app: frontend
toPorts:
- ports:
- port: "8080"
protocol: TCP
rules:
http:
- method: "GET|POST"
path: "/api/v1/.*"
headers:
- "X-Rate-Limit: .*"
3단계: mTLS 도입
# 서비스 간 mTLS 암호화
helm upgrade cilium cilium/cilium \
--namespace kube-system \
--reuse-values \
--set encryption.enabled=true \
--set encryption.type=wireguard \
--set serviceMesh.enableMutualTLS=true
가중치 기반 트래픽 분할:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: canary-deployment
spec:
parentRefs:
- name: api-gateway
rules:
- matches:
- path:
type: PathPrefix
value: /api/v2
backendRefs:
- name: api-v2-stable
port: 80
weight: 90
- name: api-v2-canary
port: 80
weight: 10
사용자 기반 A/B 테스트:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: ab-test-route
spec:
parentRefs:
- name: api-gateway
rules:
# 베타 사용자
- matches:
- headers:
- name: "X-User-Type"
value: "beta"
backendRefs:
- name: api-beta
port: 80
# 일반 사용자
- backendRefs:
- name: api-stable
port: 80
증상:
진단 단계:
# 1. 정책 문법 확인
kubectl get ciliumnetworkpolicy -o yaml | yq '.items[].spec'
# 2. 엔드포인트 매칭 확인
kubectl exec -n kube-system ds/cilium -c cilium-agent -- \
cilium-dbg endpoint list -o json | jq '.[] | select(.status.policy.realized != null)'
# 3. 정책 프로그래밍 상태 확인
kubectl exec -n kube-system ds/cilium -c cilium-agent -- \
cilium-dbg policy get -o json | jq '.policy.revision'
해결 방안:
# 라벨 확인 및 수정
kubectl get pods --show-labels | grep app=backend
# 네임스페이스 라벨 확인
kubectl get namespace --show-labels
# 정책 재적용
kubectl delete ciliumnetworkpolicy problematic-policy
kubectl apply -f fixed-policy.yaml
증상:
진단 단계:
# 1. L7 프록시 상태 확인
kubectl exec -n kube-system ds/cilium -c cilium-agent -- \
cilium status | grep -i proxy
# 2. Envoy 설정 확인
kubectl exec -n kube-system ds/cilium -c cilium-agent -- \
cilium-dbg proxy statistics
# 3. 엔드포인트 L7 정책 확인
kubectl exec -n kube-system ds/cilium -c cilium-agent -- \
cilium-dbg endpoint get <endpoint-id> -o json | jq '.status.policy.l7'
해결 방안:
# L7 프록시 재시작
kubectl exec -n kube-system ds/cilium -c cilium-agent -- \
cilium-dbg endpoint regenerate <endpoint-id>
# 정책 우선순위 확인 및 조정
kubectl annotate ciliumnetworkpolicy l7-policy \
policy.cilium.io/priority="100"
증상:
진단 단계:
# 1. WireGuard 상태 확인
wg show all
# 2. 핸드셰이크 시간 확인
wg show all latest-handshakes
# 3. 엔드포인트 연결성 확인
ping <peer-endpoint-ip>
# 4. 포트 방화벽 확인
ss -ulnp | grep 51871
iptables -L | grep 51871
해결 방안:
# 키 재생성
kubectl delete secret -n kube-system cilium-wireguard-keys
kubectl rollout restart -n kube-system ds/cilium
# 방화벽 규칙 확인
ufw allow 51871/udp
iptables -A INPUT -p udp --dport 51871 -j ACCEPT
증상:
진단 단계:
# 1. CPU 사용률 모니터링
top -p $(pidof cilium-agent)
# 2. 암호화 통계 확인
cat /proc/net/dev | grep cilium_wg0
# 3. WireGuard 통계
wg show all transfer
# 4. 커널 모듈 확인
lsmod | grep wireguard
modinfo wireguard
해결 방안:
# CPU 리소스 증대
kubectl patch daemonset cilium -n kube-system --patch='
{
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "cilium-agent",
"resources": {
"limits": {
"cpu": "2000m"
}
}
}
]
}
}
}
}'
# 하드웨어 가속 활용
grep aes /proc/cpuinfo
echo 'options wireguard prefer_chacha20_poly1305=0' > /etc/modprobe.d/wireguard.conf
증상:
진단 단계:
# 1. Ingress Controller Pod 상태
kubectl get pods -n kube-system -l app.kubernetes.io/name=cilium-ingress
# 2. 서비스 엔드포인트 확인
kubectl get endpoints -n kube-system cilium-ingress
# 3. 백엔드 서비스 상태
kubectl get endpoints <backend-service>
# 4. Ingress 상태 확인
kubectl describe ingress <ingress-name>
해결 방안:
# Ingress Controller 재시작
kubectl rollout restart -n kube-system deployment/cilium-ingress
# 백엔드 연결성 확인
kubectl exec -n kube-system deployment/cilium-ingress -- \
curl <backend-service>:<port>
# Ingress 클래스 확인
kubectl patch ingress <ingress-name> -p='
{
"spec": {
"ingressClassName": "cilium"
}
}'
증상:
진단 단계:
# 1. Gateway 상태 확인
kubectl describe gateway <gateway-name>
# 2. HTTPRoute 상태 확인
kubectl describe httproute <route-name>
# 3. Gateway Controller 로그
kubectl logs -n kube-system -l app.kubernetes.io/name=cilium-gateway
# 4. 호스트 헤더 확인
curl -v -H "Host: <hostname>" http://<gateway-ip>/
해결 방안:
# Gateway Controller 재시작
kubectl rollout restart -n kube-system deployment/cilium-gateway
# 호스트명 매칭 확인
kubectl patch httproute <route-name> --patch='
{
"spec": {
"hostnames": ["api.example.com", "*.example.com"]
}
}'
# 드롭 원인 분석
hubble observe --verdict DROPPED --last 1000 | \
jq -r '.drop_reason_desc' | sort | uniq -c
# eBPF 맵 상태 확인
kubectl exec -n kube-system ds/cilium -c cilium-agent -- \
cilium-dbg bpf metrics
# 메트릭 기반 분석
kubectl exec -n kube-system ds/cilium -c cilium-agent -- \
curl -s localhost:9962/metrics | grep drop_count
# Cilium Agent 메모리 사용량
kubectl top pods -n kube-system -l k8s-app=cilium
# eBPF 맵 메모리 사용량
kubectl exec -n kube-system ds/cilium -c cilium-agent -- \
cilium-dbg bpf metrics | grep -i memory
# 가비지 컬렉션 강제 실행
kubectl exec -n kube-system ds/cilium -c cilium-agent -- \
cilium-dbg bpf ct flush global
처리량 테스트:
# iperf3 서버 배포
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: iperf3-server
labels:
app: iperf3-server
spec:
containers:
- name: iperf3
image: networkstatic/iperf3
args: ["-s", "-p", "5201"]
ports:
- containerPort: 5201
EOF
# 클라이언트 테스트
kubectl run iperf3-client --rm -it --image=networkstatic/iperf3 -- \
-c iperf3-server -p 5201 -t 60 -P 4
# 결과 분석
# - 암호화 전후 처리량 비교
# - CPU 사용률 모니터링
# - 메모리 사용량 확인
지연시간 테스트:
# 기본 ping 테스트
kubectl exec iperf3-client -- ping -c 100 iperf3-server
# hping3를 통한 상세 분석
kubectl exec iperf3-client -- hping3 -S -p 80 -c 100 iperf3-server
# 결과 분석
# - 평균 RTT
# - 지터 (변동성)
# - 패킷 손실률
정책 적용 오버헤드 측정:
# 정책 없는 상태에서 측정
kubectl delete ciliumnetworkpolicy --all
# 기준 성능 측정
kubectl exec iperf3-client -- iperf3 -c iperf3-server -t 30
# 복잡한 정책 적용 후 재측정
kubectl apply -f complex-policies.yaml
kubectl exec iperf3-client -- iperf3 -c iperf3-server -t 30
# 성능 차이 분석
# Cilium 확장 메트릭 활성화
helm upgrade cilium cilium/cilium \
--namespace kube-system \
--reuse-values \
--set prometheus.enabled=true \
--set prometheus.metrics="+cilium_endpoint_regenerations_total,+cilium_policy_verdict_total,+cilium_drop_count_total,+cilium_forward_count_total"
# Jaeger 설치
kubectl apply -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/main/deploy/crds/jaegertracing.io_jaegers.yaml
kubectl apply -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/main/deploy/operator.yaml
# Cilium과 Jaeger 연동
helm upgrade cilium cilium/cilium \
--namespace kube-system \
--reuse-values \
--set hubble.enabled=true \
--set hubble.relay.enabled=true \
--set hubble.ui.enabled=true \
--set hubble.export.static.enabled=true \
--set hubble.export.static.backends.jaeger.endpoint="jaeger-collector:14268"
고급 보안 기능 마스터:
Service Mesh 기능 구현:
보안 모니터링 및 운영:
엔터프라이즈 보안 설계:
Service Mesh 운영:
보안 정책 관리:
암호화 운영:
멀티클러스터 보안:
하이브리드 클라우드 보안:
고급 보안 기능: