DevOps/Kubernetes

[kubernetes] Helm으로 nginx ingress controller 설치하기

Henu 2022. 4. 4. 09:38

일반적으로 사용하는 helm의 stable repo가 업데이트를 중단했고,

k8s는 빠르게 업데이트 되는 중이다.

 

stable/nginx-ingress는 사용하기엔 너무 옛날 버전이라서, 

k8s에서 따로 배포하는 ingress-nginx repo를 사용해 ingress-controller를 설정해 보았다.

 

 

 

nginx podservice 생성

# mynginx.yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: mynginx
  name: mynginx
spec:
  containers:
  - image: nginx:1.16
    name: mynginx
    resources: {}
  restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: nginxsvc
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: mynginx

Service의 Type은 ClusterIP로 설정한다.

 

 

kubectl apply -f mynginx.yaml

 

 

 

helm repo 추가

 

GitHub - kubernetes/ingress-nginx: NGINX Ingress Controller for Kubernetes

NGINX Ingress Controller for Kubernetes. Contribute to kubernetes/ingress-nginx development by creating an account on GitHub.

github.com

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

 

 

 

Ingress namespace 생성

kubectl create ns ingress-nginx

 

 

 

helm repo update & search

helm repo update

helm search repo ingress-nginx

 

 

 

helm install ingress-nginx

helm install ingress-nginx ingress-nginx/ingress-nginx -n ingress-nginx

 

 

kubectl get pod -n ingress-nginx

kubectl get svc -n ingress-nginx

ingress가 구동되었다.

 

 

 

ingress-controller 생성

# mynginx-ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations: 
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /
  name: mynginx-ingress
spec:
  rules:
  # - host: -> domain이 없는 경우 생략 가능
  - http:
      paths:
      - path: /nginx
        pathType: Prefix
        backend:
          service:
            name: nginxsvc
            port:
              number: 80

 

kubectl apply -f mynginx-ingress.yaml

kubectl get ing

 

 

추가사항
Error from server (InternalError): error when creating "aomd-ingress.yaml": Internal error occurred: failed calling webhook "validate.nginx.ingress.kubernetes.io": failed to call webhook: Post "https://ingress-nginx-controller-admission.ingress-nginx.svc:443/networking/v1/ingresses?timeout=10s": context deadline exceeded

ingress controller 가 제대로 생성되지 않고, 위와 같은 에러가 발생한다면

 

동작에 직접적인 영향을 미치지 않는 webhook을 제거하면 된다.

kubectl delete validatingwebhookconfiguration ingress-nginx-admission

 

 

연결 확인

 

참조

 

인그레스(Ingress)

FEATURE STATE: Kubernetes v1.19 [stable] 클러스터 내의 서비스에 대한 외부 접근을 관리하는 API 오브젝트이며, 일반적으로 HTTP를 관리함. 인그레스는 부하 분산, SSL 종료, 명칭 기반의 가상 호스팅을 제공

kubernetes.io

 

 

Installation Guide - NGINX Ingress Controller

Installation Guide There are multiple ways to install the NGINX ingress controller: with Helm, using the project repository chart; with kubectl apply, using YAML manifests; with specific addons (e.g. for minikube or MicroK8s). On most Kubernetes clusters,

kubernetes.github.io

 

 

Rewrite - NGINX Ingress Controller

Rewrite This example demonstrates how to use Rewrite annotations. Prerequisites You will need to make sure your Ingress targets exactly one Ingress controller by specifying the ingress.class annotation, and that you have an ingress controller running in yo

kubernetes.github.io