[Kubernetes] services

최대 1 분 소요

services

  • 포드의 문제점

 포드는 일시적으로 생성한 컨테이너의 집합
때문에 포드가 지속적으로 생겨났을 때 서비스를 하기에 적합하지 않음
IP 주소의 지속적인 변동, 로드밸런싱을 관리해줄 또 다른 개체가 필요
이 문제를 해결하기위해 서비스라는 리소스가 존재



  • 서비스를 노출하는 3가지 방법

NodePort: 노드의 자체 포트를 사용하여 포드로 리다이렉션
 LoadBalancer: 외부 게이트웨이를 사용해 노드 포트로 리다이렉션
ingress: 하나의 IP 주소를 통해 여러 서비스를 제공하는 특별한 메커니즘 (nginx proxy와 비슷)



  • NodePort의 서비스 패킷 흐름

image.png
[ 출처 :  https://kubernetes.io/docs/concepts/services-networking/service/ ]


  • 노드포트 생성
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: MyApp
  ports:
      # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
    - port: 80
      targetPort: 80
      # Optional field
      # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
      nodePort: 30007



  • 로드밸런서 생성
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
  clusterIP: 10.0.171.239
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 192.0.2.127



  • ingress 생성
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        pathType: Prefix
        backend:
          service:
            name: test
            port:
              number: 80

댓글남기기