대상: 서비스 개발자 (Service Developers)
목적: 클러스터 내 서비스를 안전하고 효율적으로 외부에 노출하는 방법 제공
kubectl, cilium-cli (Cilium CLI 설치: 링크) | 노출 레이어 | 방법 | 적합한 유즈 케이스 |
|---|---|---|
| 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 사용 시 Ingress나 LoadBalancer를 대안으로 고려하세요.
# 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
# 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
| 서비스명 | 도메인 | 사용 패턴 | 노출 방법 | 비고 |
|---|---|---|---|---|
my-web-app | app.example.com | 웹 UI, REST API | Gateway API (L7) | 인증/라우팅 규칙 추가 가능 |
spark-thrift | spark-cluster.local | JDBC 연결 (Spark SQL) | LoadBalancer (L4) | Thrift 포트 10000 노출 |
redis-cache | cache.internal | Redis 클라이언트 연결 | NodePort (L4) | 보안 요구 시 NetworkPolicy 적용 |
cilium GatewayClass로 동작 # 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
# Gateway IP 조회
kubectl get gateway my-gateway -o jsonpath='{.status.addresses[0].value}'
# curl 테스트
curl http://<GATEWAY_IP>
Spark Thrift Server 배포
helm install spark spark-operator/spark-operator --set sparkJobNamespace=default
Thrift Service 생성
apiVersion: v1
kind: Service
metadata:
name: spark-thrift
spec:
selector:
spark-role: driver
ports:
- port: 10000
targetPort: 10000
LoadBalancer Service로 노출
apiVersion: v1
kind: Service
metadata:
name: spark-thrift-lb
spec:
selector:
spark-role: driver
ports:
- port: 10000
targetPort: 10000
type: LoadBalancer
JDBC 연결
String url = "jdbc:spark://<EXTERNAL_IP>:10000";
Connection conn = DriverManager.getConnection(url, "user", "password");
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
Q: Cilium 1.8에서 Gateway API를 사용할 수 없나요?
A: Gateway API는 Cilium 1.11+부터 지원됩니다. Cilium 1.8 사용 시 Ingress나 LoadBalancer를 대체 방법으로 활용하세요.
Q: Spark JDBC 연결 시 보안을 강화하려면?
A: TLS 암호화를 위해 Spark Thrift Server에 SSL 설정 후, LoadBalancer Service와 함께 TLS 종료 구성을 추천합니다.
Q: L4 노출 시 트래픽 모니터링은 어떻게 하나요?
A: Cilium의 cilium monitor 명령어나 Grafana 대시보드를 통해 실시간 트래픽 분석이 가능합니다.
이 가이드를 통해 서비스를 안전하고 효율적으로 외부에 노출할 수 있습니다. 추가 문의사항은 Cilium 공식 문서를 참조하세요.