본문 바로가기

리눅스

Helm을 사용하여 Ingress Controller를 설치하는 방법

반응형

Helm을 사용하여 Ingress Controller를 설치하는 방법

Nginx Ingress Controller, Traefik, HAProxy 등의 Ingress Controller 중 Nginx Ingress Controller를 사용하는 방법입니다.

Nginx Ingress Controller 설치

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
"ingress-nginx" has been added to your repositories
helm repo update
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "ingress-nginx" chart repository
Update Complete. ⎈Happy Helming!⎈
helm install nginx-ingress ingress-nginx/ingress-nginx
$ helm install nginx-ingress ingress-nginx/ingress-nginx
NAME: nginx-ingress
LAST DEPLOYED: Fri Feb 16 23:52:39 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The ingress-nginx controller has been installed.
It may take a few minutes for the load balancer IP to be available.
You can watch the status by running 'kubectl get service --namespace default nginx-ingress-ingress-nginx-controller --output wide --watch'

An example Ingress that makes use of the controller:
  apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: example
    namespace: foo
  spec:
    ingressClassName: nginx
    rules:
      - host: www.example.com
        http:
          paths:
            - pathType: Prefix
              backend:
                service:
                  name: exampleService
                  port:
                    number: 80
              path: /
    # This section is only required if TLS is to be enabled for the Ingress
    tls:
      - hosts:
        - www.example.com
        secretName: example-tls

If TLS is enabled for the Ingress, a Secret containing the certificate and key must also be provided:

  apiVersion: v1
  kind: Secret
  metadata:
    name: example-tls
    namespace: foo
  data:
    tls.crt: <base64 encoded cert>
    tls.key: <base64 encoded key>
  type: kubernetes.io/tls

참고

  • nginx-deployment.yaml 파일에는 Nginx를 실행하는 Pod를 정의하고 배포합니다.
  • nginx-service.yaml 파일에는 Nginx Pod에 대한 Kubernetes 서비스를 정의합니다.
  • ingress.yaml 파일에는 외부에서 Nginx에 접근하기 위한 Ingress 리소스를 정의합니다.
  • deployment(pod) 생성
vim nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
kubectl apply -f nginx-deployment.yaml
$ kubectl apply -f nginx-deployment.yaml
deployment.apps/nginx-deployment created
kubectl get pod -l app=nginx
$ kubectl get pod -l app=nginx
NAME                                READY   STATUS    RESTARTS   AGE
nginx-deployment-7c79c4bf97-5w2gv   1/1     Running   0          18m
nginx-deployment-7c79c4bf97-m55b6   1/1     Running   0          18m
nginx-deployment-7c79c4bf97-t9tqn   1/1     Running   0          18m
728x90
  • service 생성
vim nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: ClusterIP
$ kubectl apply -f nginx-service.yaml
service/nginx-service created
kubectl get svc nginx-service
$ kubectl get svc nginx-service
NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
nginx-service   ClusterIP   10.108.94.236   <none>        80/TCP    3m56s

Ingress 리소스 생성

Nginx Ingress Controller를 사용하여 외부에서 Nginx에 접근할 수 있도록 Ingress 리소스를 생성합니다.

vim ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
spec:
  rules:
  - host: example.com  # 외부에서 접근할 도메인을 지정합니다.
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx-service  # Nginx 서비스 이름을 지정합니다.
            port:
              number: 80
kubectl apply -f ingress.yaml
$ kubectl apply -f ingress.yaml
ingress.networking.k8s.io/nginx-ingress created
kubectl get ingress
$ kubectl get ingress
NAME            CLASS    HOSTS         ADDRESS   PORTS   AGE
nginx-ingress   <none>   example.com             80      18m

 

이제 외부에서 example.com과 같은 도메인을 사용하여 Nginx에 액세스할 수 있습니다. 해당 도메인이 DNS에 등록되어 있어야 합니다.

curl http://example.com --resolve example.com:80:10.108.94.236
$ curl http://example.com --resolve example.com:80:10.108.94.236
nginx-deployment-7c79c4bf97-m55b6

 

728x90
반응형