Cilium 1.8을 이용한 서비스 외부 노출 가이드

진웅·2025년 9월 11일

CILIUM

목록 보기
11/14

Cilium 1.8을 이용한 서비스 외부 노출 가이드

대상: 서비스 개발자 (Service Developers)
목적: 클러스터 내 서비스를 안전하고 효율적으로 외부에 노출하는 방법 제공

1. 서비스 개발자 활용 방법 (Usage Guide)

1.1 사전 준비 (Prerequisites)

  • 클러스터 환경: Kubernetes 클러스터 (v1.20+) + Cilium 1.8 설치 완료
  • 도구: kubectl, cilium-cli (Cilium CLI 설치: 링크)
  • 네트워크 정책: Cilium의 eBPF 기반 네트워킹 활성화 (기본 설정으로 적용됨)

1.2 서비스 노출 접근법 선택 (Exposure Method Selection)

노출 레이어방법적합한 유즈 케이스
L7 (HTTP/HTTPS)Gateway API / Ingress웹 애플리케이션, REST API, gRPC
L4 (TCP/UDP)LoadBalancer Service / TCPRoute데이터베이스(JDBC), 메시지 큐, Spark 연결

주의: Gateway API는 Cilium 1.11+에서 지원됩니다. Cilium 1.8 사용 시 IngressLoadBalancer를 대안으로 고려하세요.


1.3 노출 단계별 가이드 (Step-by-Step)

Case 1: L7 노출 (웹 애플리케이션 예시)

# 1. Deployment 생성
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-web-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-web-app
  template:
    metadata:
      labels:
        app: my-web-app
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80

# 2. Service 생성 (ClusterIP)
apiVersion: v1
kind: Service
metadata:
  name: my-web-service
spec:
  selector:
    app: my-web-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

# 3. Gateway API (Cilium 1.11+) 또는 Ingress 생성
# Gateway API 예시 (Cilium 1.11+ 필요):
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
  name: my-gateway
spec:
  gatewayClassName: cilium
  listeners:
  - name: http
    port: 80
    protocol: HTTP

apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: my-route
spec:
  parentRefs:
  - name: my-gateway
  rules:
  - backendRefs:
    - name: my-web-service
      port: 80

Case 2: L4 노출 (Spark JDBC 연결 예시)

# 1. Spark Thrift Server 배포 (예시)
helm repo add spark-operator https://googlecloudplatform.github.io/spark-on-k8s-operator
helm install spark spark-operator/spark-operator

# 2. Spark Thrift Service 생성
apiVersion: v1
kind: Service
metadata:
  name: spark-thrift
spec:
  selector:
    spark-role: driver  # Thrift 서버가 실행되는 포드 태그
  ports:
  - name: thrift
    port: 10000
    targetPort: 10000
  type: ClusterIP  # 초기에는 ClusterIP로 시작

# 3. LoadBalancer Service로 노출
apiVersion: v1
kind: Service
metadata:
  name: spark-thrift-lb
spec:
  selector:
    spark-role: driver
  ports:
  - name: thrift
    port: 10000
    targetPort: 10000
  type: LoadBalancer  # 외부 IP 할당

# 4. JDBC 연결 확인
# 외부 IP 조회: kubectl get svc spark-thrift-lb
# JDBC URL: jdbc:spark://<EXTERNAL_IP>:10000

2. 서비스 노출 정보 테이블 (Service Exposure Details)

서비스명도메인사용 패턴노출 방법비고
my-web-appapp.example.com웹 UI, REST APIGateway API (L7)인증/라우팅 규칙 추가 가능
spark-thriftspark-cluster.localJDBC 연결 (Spark SQL)LoadBalancer (L4)Thrift 포트 10000 노출
redis-cachecache.internalRedis 클라이언트 연결NodePort (L4)보안 요구 시 NetworkPolicy 적용

3. Gateway API 사용 예시 (Ingress 대체)

3.1 Gateway API란?

  • Kubernetes Native API로, Ingress보다 유연한 L7/L4 라우팅 지원
  • Cilium 1.11+에서 cilium GatewayClass로 동작

3.2 리소스 생성 예시

# Gateway (L7 수신기)
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
  name: my-gateway
spec:
  gatewayClassName: cilium
  listeners:
  - name: http
    port: 80
    protocol: HTTP

# HTTPRoute (라우팅 규칙)
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: my-route
spec:
  parentRefs:
  - name: my-gateway
  rules:
  - matches:
    - path:
        type: Prefix
        value: /
    backendRefs:
    - name: my-web-service
      port: 80

3.3 테스트

# Gateway IP 조회
kubectl get gateway my-gateway -o jsonpath='{.status.addresses[0].value}'

# curl 테스트
curl http://<GATEWAY_IP>

4. L4 레벨 노출 방법 (JDBC 연결 시나리오)

4.1 방법론

  • LoadBalancer Service: 클러스터 외부 IP 자동 할당 (클라우드 환경 권장)
  • NodePort: 모든 노드의 특정 포트로 트래픽 전달 (로컬 테스트 용이)
  • Cilium BGP: 온프레미스 환경에서 BGP를 통해 직접 라우팅 (고급 설정)

4.2 Spark JDBC 연결 예시 (LoadBalancer)

  1. Spark Thrift Server 배포

    helm install spark spark-operator/spark-operator --set sparkJobNamespace=default
  2. Thrift Service 생성

    apiVersion: v1
    kind: Service
    metadata:
      name: spark-thrift
    spec:
      selector:
        spark-role: driver
      ports:
      - port: 10000
        targetPort: 10000
  3. LoadBalancer Service로 노출

    apiVersion: v1
    kind: Service
    metadata:
      name: spark-thrift-lb
    spec:
      selector:
        spark-role: driver
      ports:
      - port: 10000
        targetPort: 10000
      type: LoadBalancer
  4. JDBC 연결

    String url = "jdbc:spark://<EXTERNAL_IP>:10000";
    Connection conn = DriverManager.getConnection(url, "user", "password");

4.3 NodePort 사용 예시 (로컬 테스트)

apiVersion: v1
kind: Service
metadata:
  name: spark-thrift-nodeport
spec:
  selector:
    spark-role: driver
  ports:
  - port: 10000
    targetPort: 10000
    nodePort: 30000  # 30000~32767 범위에서 선택
  type: NodePort
# 로컬에서 연결
jdbc:spark://<NODE_IP>:30000

5. FAQ

Q: Cilium 1.8에서 Gateway API를 사용할 수 없나요?
A: Gateway API는 Cilium 1.11+부터 지원됩니다. Cilium 1.8 사용 시 IngressLoadBalancer를 대체 방법으로 활용하세요.

Q: Spark JDBC 연결 시 보안을 강화하려면?
A: TLS 암호화를 위해 Spark Thrift Server에 SSL 설정 후, LoadBalancer Service와 함께 TLS 종료 구성을 추천합니다.

Q: L4 노출 시 트래픽 모니터링은 어떻게 하나요?
A: Cilium의 cilium monitor 명령어나 Grafana 대시보드를 통해 실시간 트래픽 분석이 가능합니다.


이 가이드를 통해 서비스를 안전하고 효율적으로 외부에 노출할 수 있습니다. 추가 문의사항은 Cilium 공식 문서를 참조하세요.

profile
bytebliss

0개의 댓글