spark-connect-cluster (NodePort 31116, TargetPort 15002)user-namespaceapiVersion: "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"
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
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
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의 실제 레이블에 맞게 수정 필요
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
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
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
kubectl apply -f cilium-lb-pool.yaml
kubectl apply -f l2-announcement-policy.yaml
kubectl apply -f spark-connect-gateway.yaml
kubectl apply -f spark-connect-lb-service.yaml
kubectl apply -f spark-connect-tcproute.yaml
kubectl apply -f spark-ui-httproute.yaml
kubectl get svc -n user-namespace
kubectl get gateway -n user-namespace
kubectl get tcproute,httproute -n user-namespace
kubectl get ciliumloadbalancerippool
kubectl get ciliuml2announcementpolicy
# Spark Connect 테스트
telnet 10.40.22.249 15002
# Spark UI 접근 테스트
curl http://10.40.22.249:4040
kubectl describe svc spark-connect-cluster-lb -n user-namespace
kubectl logs -n kube-system -l k8s-app=cilium
kubectl describe gateway spark-connect-gateway -n user-namespace
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를 활용한 구조로 변환할 수 있습니다.
핵심 변경사항:
주요 장점:
실제 환경에 맞게 SparkApplication의 레이블과 포트 설정을 확인하여 조정