kok202
쿠버네티스 입문 - 04 - 인그레스

2020. 4. 4. 21:00[정리] 기능별 개념 정리/Kubernetes

인그레스

인그레스는 클러스터 외부에서 안에 있는 파드로 접근할 때 사용된다.

인그레스는 클러스터 외부에서 안으로 접근할 때 요청을 어떻게 처리할지 정의해둔 규칙 모음이다.

인그레스 자체는 그냥 규칙을 정의해둔 자원이다.

인그레스 컨트롤러가 실제로 인그레스를 동작시킨다.

쿠버네티스에서 제공하는 공식적인 인그레스 컨트롤러는 ingress-gce, ingress-nginx 이다.

서비스와의 차이점은 주로 L7 영역의 통신을 담당해서 처리한다는 점이다.

인그레스 컨트롤러에서 파드로 직접 접근할 수도 있으므로 중간에 서비스를 생략하면 좀 더 좋은 성능을 낼 수 도 있다.

 

 

 

 

인그레스 샘플

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  tls:
  - hosts:
    - foo.bar.com
    secretName: mySecret
  rules:
  - host: foo.bar.com
    http:
      paths:
      - path: /foos1
        backend:
          serviceName: s1
          servicePort: 80
      - path: /bars2
        backend:
          serviceName: s2
          servicePort: 80

.metadata.annotations : 인그레스를 설정하는 필드. 위의 예시의 경우 / 경로로 리다이렉트 하라는 뜻이다.

.spec.rules[].http.paths[] : http 요청이 어떤 경로에서 들어오는지 명시한다.

.spec.rules[].http.backend.serviceName : 해당 http 요청이 들어오면 지정한 서비스로 요청을 보낸다.

.spec.rules[].http.backend.servicePort : 해당 http 요청이 들어오면 지정한 서비스의 지정한 포트로 요청을 보낸다.

.spec.tls[].hosts[] : 인증서를 사용하는 경우 호스트 이름 설정

.spec.tls[].secretName : 인증서에 사용되는 시크릿 정보 

 

 

 

인그레스에 SSL을 위한 인증서를 시크릿으로 등록

tls.key

-----BEGIN CERTIFICATE-----
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAA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