Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Info
iconfalse
Info

트래픽 분산을 위해 Pod를 여러개로 구성할때, EndPoint를 제공하여 IP주소의 변동 및 로드밸런싱을 가능하게 해줍니다.

Info
iconfalse
titlewww.boanproject.com

Service Type

Info

ClusterIP (default)

  • 외부에서접속이 불가하며 Cluster내부에서만 접근 가능한 서비스타입

NodePort

  • NodePort를 통해 외부네트워크에서 접속가능한 서비스타입
  • 30000-32767 범위의 포트가 자동 할당되며, 포트를 직접 명시 할 수 있습니다.
  • 운영환경에서는 사용하기에 적절하지 않음

LoadBalancer

  • LB를 통해 PublicIP를 할당 받아 Public Endpoint를 제공합니다.
  • 클라우드의 환경의 경우 클라우드 LB를 사용합니다.
  • On-premise구축시에는 LB가 없으며, 3rdParty LB의 도움을 받아야 합니다.3Party LoadBalancer의 도움을 받아 외부에서 접속 가능한 서비스타입

Service Manifest

Info
iconfalse

https://dev-k8sref-io.web.app/docs/services/service-v1/

Info
iconfalse
Code Block
titlenginx-svc.yaml
linenumberstrue
apiVersion: v1
kind: Service
metadata:
  labels:
	app: myapp-svc
    type: front-end
  name: nginx-svc
spec:
  type: ClusterIP
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    type: front-end


Service 실습

ClusterIP (default)

Info
iconfalse

ClusterIP

  • back-end
  • redis


Info
iconfalse

Service 대상 Deployment

Code Block
titlenginx-deploy.yaml
linenumberstrue
collapsetrue
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deploy
  labels:
    app: myapp-deploy
    type: front-end
spec:
  template:
    metadata:
      name: nginx
      labels:
        app: myapp
        type: front-end
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2
          ports:
            - containerPort: 80
  selector:
    matchLabels:
      type: front-end
  replicas: 3
Code Block
titlenginx-svc.yaml
linenumberstrue
apiVersion: v1
kind: Service
metadata:
  labels:
	app: myapp-svc
    type: front-end
  name: nginx-svc
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    type: front-end
Code Block
linenumberstrue
sansae@sansaeAir15m2 k8s-lab-workspace % k apply -f nginx-svc.yaml 
service/nginx-svc created
sansae@sansaeAir15m2 k8s-lab-workspace % k get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.0.0.1       <none>        443/TCP   23h
nginx-svc    ClusterIP   10.0.133.111   <none>        80/TCP    5s
sansae@sansaeAir15m2 k8s-lab-workspace % k describe svc nginx-svc 
Name:              nginx-svc
Namespace:         default
Labels:            app=myapp-svc
                   type=front-end
Annotations:       <none>
Selector:          type=front-end
Type:              ClusterIP
IP Family Policy:  SingleStack
IP Families:       IPv4
IP:                10.0.133.111
IPs:               10.0.133.111
Port:              <unset>  80/TCP
TargetPort:        80/TCP
Endpoints:         10.244.0.75:80,10.244.0.76:80,10.244.0.77:80
Session Affinity:  None
Events:            <none>


Code Block
titlesooabia/network-utils
linenumberstrue
sansae@sansaeAir15m2 k8s-lab-workspace % k get svc
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.0.0.1       <none>        443/TCP   24h
nginx-svc    ClusterIP   10.0.133.111   <none>        80/TCP    61m

sansae@sansaeAir15m2 k8s-lab-workspace % k run util --image=sooabia/network-utils
pod/util created

sansae@sansaeAir15m2 k8s-lab-workspace % k exec -it util -- bash
root@util:/# curl 10.0.133.111
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>



...

Info

Code Block
titlenginx-svc-lb.yaml
linenumberstrue
apiVersion: v1
kind: Service
metadata:
  labels:
    app: myapp-svc
    type: front-end
  name: nginx-svc-lb
spec:
  type: LoadBalancer
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    type: front-end
Code Block
sansae@sansaeAir15m2 k8s-lab-workspace % k apply -f nginx-svc-lb.yaml 
service/nginx-svc-lb created

sansae@sansaeAir15m2 k8s-lab-workspace % k get svc
NAME                 TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
kubernetes           ClusterIP      10.0.0.1       <none>        443/TCP        29h
nginx-svc            ClusterIP      10.0.133.111   <none>        80/TCP         5h50m
nginx-svc-lb         LoadBalancer   10.0.69.70     <pending>     80:32050/TCP   5s
nginx-svc-nodeport   NodePort       10.0.159.138   <none>        80:30008/TCP   11m

sansae@sansaeAir15m2 k8s-lab-workspace % k get svc
NAME                 TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)        AGE
kubernetes           ClusterIP      10.0.0.1       <none>           443/TCP        29h
nginx-svc            ClusterIP      10.0.133.111   <none>           80/TCP         5h50m
nginx-svc-lb         LoadBalancer   10.0.69.70     20.249.176.154   80:32050/TCP   18s
nginx-svc-nodeport   NodePort       10.0.159.138   <none>           80:30008/TCP   11m
sansae@sansaeAir15m2 k8s-lab-workspace % 

LoadBalancer Type의 Service가 생성한 EXTERNAL-IP로 호출 확인

Azure Cloud Native LoadBalancer확인