k8s gateway API w/ cilium Test

진웅·2025년 9월 19일

CILIUM

목록 보기
12/14

Cilium Gateway API를 활용한 Spark Connect 클러스터 노출 설정

현재 환경 정보

  • Kubernetes: 1.33
  • Cilium: 1.17
  • Gateway API: 설치 완료 (HTTPRoute, TCPRoute 지원)
  • 현재 서비스: spark-connect-cluster (NodePort 31116, TargetPort 15002)
  • 네임스페이스: user-namespace
  • 대상 Pod: Spark Driver (SparkApplication, Spark 4.0)
  • LoadBalancer IP Pool: 10.40.22.249

1. CiliumLoadBalancerIPPool 생성

apiVersion: "cilium.io/v2alpha1"
kind: CiliumLoadBalancerIPPool
metadata:
  name: spark-connect-pool
spec:
  cidrs:
  - cidr: "10.40.22.249/32"
  serviceSelector:
    matchLabels:
      io.cilium/lb-ipam-ips: "10.40.22.249"

2. L2AnnouncementPolicy 설정

apiVersion: "cilium.io/v2alpha1"
kind: CiliumL2AnnouncementPolicy
metadata:
  name: spark-connect-l2-policy
spec:
  serviceSelector:
    matchLabels:
      io.cilium/lb-ipam-ips: "10.40.22.249"
  nodeSelector: {}
  interfaces:
  - "^eth[0-9]+"
  externalIPs: true
  loadBalancerIPs: true

3. Gateway 생성

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: spark-connect-gateway
  namespace: user-namespace
spec:
  gatewayClassName: cilium
  listeners:
  - name: spark-connect-tcp
    port: 15002
    protocol: TCP
    allowedRoutes:
      namespaces:
        from: Same
  - name: spark-connect-http
    port: 4040
    protocol: HTTP
    allowedRoutes:
      namespaces:
        from: Same

4. LoadBalancer 서비스로 변환

기존 NodePort 서비스를 LoadBalancer로 변경

apiVersion: v1
kind: Service
metadata:
  name: spark-connect-cluster-lb
  namespace: user-namespace
  labels:
    app: spark-connect-cluster
    io.cilium/lb-ipam-ips: "10.40.22.249"
  annotations:
    io.cilium/lb-ipam-ips: "10.40.22.249"
spec:
  type: LoadBalancer
  loadBalancerIP: "10.40.22.249"
  ports:
  - name: spark-connect
    port: 15002
    targetPort: 15002
    protocol: TCP
  - name: spark-ui
    port: 4040
    targetPort: 4040
    protocol: TCP
  selector:
    spark-role: driver
    # SparkApplication의 실제 레이블에 맞게 수정 필요

5. TCPRoute 설정 (Spark Connect 프로토콜용)

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TCPRoute
metadata:
  name: spark-connect-tcproute
  namespace: user-namespace
spec:
  parentRefs:
  - name: spark-connect-gateway
    sectionName: spark-connect-tcp
  rules:
  - backendRefs:
    - name: spark-connect-cluster-lb
      port: 15002
      weight: 1

6. HTTPRoute 설정 (Spark UI용)

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: spark-ui-httproute
  namespace: user-namespace
spec:
  parentRefs:
  - name: spark-connect-gateway
    sectionName: spark-connect-http
  hostnames:
  - "spark-ui.local"  # 필요에 따라 수정
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: "/"
    backendRefs:
    - name: spark-connect-cluster-lb
      port: 4040
      weight: 1

7. Gateway에 LoadBalancer IP 할당

apiVersion: v1
kind: Service
metadata:
  name: spark-connect-gateway-lb
  namespace: user-namespace
  labels:
    io.cilium/lb-ipam-ips: "10.40.22.249"
  annotations:
    io.cilium/lb-ipam-ips: "10.40.22.249"
spec:
  type: LoadBalancer
  loadBalancerIP: "10.40.22.249"
  ports:
  - name: spark-connect
    port: 15002
    targetPort: 15002
    protocol: TCP
  - name: spark-ui
    port: 4040
    targetPort: 4040
    protocol: HTTP
  selector:
    io.gateway.networking.k8s/gateway-name: spark-connect-gateway

배포 순서

  1. CiliumLoadBalancerIPPool과 L2AnnouncementPolicy 적용:
kubectl apply -f cilium-lb-pool.yaml
kubectl apply -f l2-announcement-policy.yaml
  1. Gateway 생성:
kubectl apply -f spark-connect-gateway.yaml
  1. LoadBalancer 서비스 생성:
kubectl apply -f spark-connect-lb-service.yaml
  1. Routes 설정:
kubectl apply -f spark-connect-tcproute.yaml
kubectl apply -f spark-ui-httproute.yaml

검증 및 테스트

1. 서비스 상태 확인

kubectl get svc -n user-namespace
kubectl get gateway -n user-namespace
kubectl get tcproute,httproute -n user-namespace

2. Cilium 상태 확인

kubectl get ciliumloadbalancerippool
kubectl get ciliuml2announcementpolicy

3. 연결 테스트

# Spark Connect 테스트
telnet 10.40.22.249 15002

# Spark UI 접근 테스트
curl http://10.40.22.249:4040

주의사항

  1. SparkApplication 레이블 확인: 서비스 셀렉터가 실제 Spark Driver Pod의 레이블과 일치하는지 확인
  2. 포트 충돌 방지: 기존 NodePort 서비스와 새 LoadBalancer 서비스가 동시에 실행되지 않도록 주의
  3. 네트워크 정책: Cilium Network Policy가 트래픽을 차단하지 않는지 확인
  4. DNS 설정: HTTPRoute에서 사용하는 호스트명이 적절히 설정되었는지 확인

문제 해결

LoadBalancer IP가 할당되지 않는 경우

kubectl describe svc spark-connect-cluster-lb -n user-namespace
kubectl logs -n kube-system -l k8s-app=cilium

Gateway가 Ready 상태가 되지 않는 경우

kubectl describe gateway spark-connect-gateway -n user-namespace

Route가 연결되지 않는 경우

kubectl describe tcproute spark-connect-tcproute -n user-namespace
kubectl describe httproute spark-ui-httproute -n user-namespace

Kubernetes에서 Cilium Gateway API를 활용하여 Spark Connect 클러스터를 LoadBalancer로 노출하는 설정 가이드를 제공하겠습니다.위의 설정 가이드를 통해 기존의 NodePort 서비스를 Cilium Gateway API와 LoadBalancer를 활용한 구조로 변환할 수 있습니다.

핵심 변경사항:

  1. CiliumLoadBalancerIPPool로 10.40.22.249 IP 할당
  2. L2AnnouncementPolicy로 Layer 2에서 IP 광고
  3. Gateway로 TCP/HTTP 트래픽 라우팅 엔드포인트 제공
  4. TCPRoute로 Spark Connect 프로토콜 (포트 15002) 라우팅
  5. HTTPRoute로 Spark UI (포트 4040) 라우팅

주요 장점:

  • NodePort의 포트 제한 해결
  • 고정 IP 주소로 외부 접근 가능
  • Gateway API를 통한 표준화된 라우팅
  • Cilium의 고성능 네트워킹 활용

실제 환경에 맞게 SparkApplication의 레이블과 포트 설정을 확인하여 조정

profile
bytebliss

0개의 댓글