티스토리 뷰

Cloud/Cloud Native

nginx ingress with namespace

Jacob_baek 2020. 8. 24. 17:58

nginx-ingress와 namespace

nginx-ingress는 기본적으로 모든 namespace의 resource를 control할 수 있도록 배포가 되어진다.

해당 개념과는 다르게 지정된 namespace의 resource만을 control할수 있게도 가능하다.

이번에는 지정된 namespace의 resource만 control 되는 환경에서 다른 namespace에 있는 service를 backend로 가지는 ingress를 생성하는 방법에 대하여 알아보도록 하겠다.

참고로 아래 링크에 namespace를 지정하는 방식에 대한 설명이 있으니 한번 참고해 보면 좋을듯하다.

다음 설정은 helm chart 상에서 지정하는 방식이다.

  ## Limit the scope of the controller
  ##
  scope:
    enabled: true
    namespace: "ingress"   # defaults to .Release.Namespace

실제로 위 설정을 통해 배포된 ingress의 process를 확인해보면 다음과 같이 --watch-namespace 라는 옵션이 사용되어지고 있다.

101      11454 11418  1 08:25 ?        00:00:01 /nginx-ingress-controller --default-backend-service=ingress/nginx-ingress-default-backend --election-id=ingress-controller-leader --ingress-class=nginx --configmap=ingress/nginx-ingress-controller --watch-namespace=ingress

별도의 설정이 없는 경우는 아래와 같이 "--watch-namespace" 옵션이 존재하지 않는다.

101       4559  4540  0  7월29 ?      03:08:38 /nginx-ingress-controller --default-backend-service=ingress/nginx-ingress-default-backend --election-id=ingress-controller-leader --ingress-class=nginx --configmap=ingress/nginx-ingress-controller

만약 다른 namespace의 service를 사용하고자 할 경우

만약 --watch-namespace 옵션이 사용되는 환경에서 다른 namespace의 service가 해당 ingress를 사용해야 할 경우 ingress가 동작되지 않는다. 이러한 경우 다음과 같은 resource를 생성하여 우회적으로 사용해야 한다.

다음과 같은 가정을 하고 진행한다.

  • A namespace (ingress가 속한)
  • B namespace (ingress를 사용하고자 하는 service가 존재하는)
  • App은 B namespace에 생성되어 있고 service가 grafana라 가정한다.
    (실제 grafana.lma.svc.cluster.local 로 다른 pod에서 연결이 이루어지는 환경이다.)

과정은 다음과 같다.

  1. A namespace에 ExternalName type Service 생성한다.

    apiVersion: v1
    kind: Service
    metadata:
    name: grafana-external
    namespace: ingress
    spec:
    type: ExternalName
    externalName: grafana.lma.svc.cluster.local
  2. A namespace에 ingress를 생성한다.

    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
    annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
    labels:
    app.kubernetes.io/instance: grafana
    app.kubernetes.io/name: grafana
    app.kubernetes.io/version: 7.0.5
    name: grafana
    namespace: ingress
    spec:
    rules:
    - host: lma.example.com
    http:
      paths:
      - backend:
          serviceName: grafana-external
          servicePort: 80
        path: /
    tls:
    - hosts:
    - lma.example.com
    secretName: example-certs
    status:
    loadBalancer: {}

ExternalName 이란?
지정된 namespace가 아닌 외부의 namespace혹은 domain 에 매핑되는 서비스를 찾아갈수 있도록 해준다.
proxy처럼 중간자 역할을 수행한다.

참고사이트

'Cloud > Cloud Native' 카테고리의 다른 글

starboard  (0) 2020.10.03
Octant  (0) 2020.10.02
Make Helm chart repo  (0) 2020.07.23
Accident for deleting pvc  (0) 2020.06.23
minikube start in WSL2  (0) 2019.12.07
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함