Service

ClusterIP, NodePort, LoadBalancer
Service with ClusterIP, NodePort, LoadBalancer.


1. ClusterIP


Service with ClusterIP for Kubernetes.

1-1) Pod

apiVersion: v1
kind: Pod
metadata:
  name: pod-1
  labels:
     app: pod
spec:
  nodeSelector:
    kubernetes.io/hostname: k8s-node1
  containers:
  - name: container
    image: kubetm/app
    ports:
    - containerPort: 8080

1-2) Service

apiVersion: v1
kind: Service
metadata:
  name: svc-1
spec:
  selector:
    app: pod
  ports:
  - port: 9000
    targetPort: 8080
curl 10.104.103.107:9000/hostname


2. NodePort


Service with NodePort for Kubernetes.

2-1) Service

apiVersion: v1
kind: Service
metadata:
  name: svc-2
spec:
  selector:
    app: pod
  ports:
  - port: 9000
    targetPort: 8080
    nodePort: 30001
  type: NodePort
  externalTrafficPolicy: Local
  • kubernetes dahsboard UI Port가 30000으로 변경되어 해당 실습 port는 30001로 하시면 됩니다

3. Load Balancer


Service with LoadBalancer for Kubernetes.

3-1) Service

apiVersion: v1
kind: Service
metadata:
  name: svc-3
spec:
  selector:
    app: pod
  ports:
  - port: 9000
    targetPort: 8080
  type: LoadBalancer
kubectl get service svc-3


Sample Yaml


Service

apiVersion: v1
kind: Service
metadata:
  name: svc-3
spec:
  selector:             # Pod의 Label과 매칭
    app: pod
  ports:
  - port: 9000          # Service 자체 Port
    targetPort: 8080    # Pod의 Container Port
  type: ClusterIP, NodePort, LoadBalancer  # 생략시 ClusterIP
  externalTrafficPolicy: Local, Cluster    # 트래픽 분배 역할


kubectl


Get

defalut 이름의 Namespace에서 svc-3 이름의 Service 조회

kubectl get service svc-3 -n defalut


Tips


NodePort

  • Node Port의 범위 : 30000~32767


Referenece


Kubernetes

Others