🔹Kubernetes

Ingress Controller 설치

terranbin 2025. 2. 2. 10:31
728x90
SMALL

[전제 조건]

✔ Calico 정상 실행 상태

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

✔ 실행 여부 확인

kubectl get pods -n kube-system | grep calico

 출력 (Running 상태여야 함)

calico-kube-controllers-658d97c59c-krt5p   1/1     Running   0          112s
calico-node-6sbmz                          1/1     Running   0          112s
calico-node-gsn8s                          1/1     Running   0          112s
calico-node-hwcsl                          1/1     Running   0          112s

[절차]

1️⃣ Ingress Controller(Nginx) 설치
2️⃣ Nginx Deployment & Service 배포 (/var/www/html 데이터 마운트)
3️⃣ Ingress 리소스 생성 (mywebsite.local)


(1) Ingress Controller 설치 (Nginx)

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/baremetal/deploy.yaml

설치 확인

kubectl get ns

출력 (Active상태여야 함)

NAME              STATUS   AGE
default           Active   56m
ingress-nginx     Active   43s #이녀석
kube-node-lease   Active   56m
kube-public       Active   56m
kube-system       Active   56m

Ingress 서비스 확인 (LoadBalancer 또는 NodePort)

kubectl get svc -n ingress-nginx

출력

NAME                                 TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             LoadBalancer   10.108.40.215   <none>        80:31018/TCP,443:32354/TCP   8m26s
ingress-nginx-controller-admission   ClusterIP      10.108.206.98   <none>        443/TCP                      8m26s

👉 Portforwarding 되어 있는 것 확인 가능

- http -> 31018 port 이용

- https -> 32354 port 이용


(2) Nginx 서비스 생성 (ClusterIP)

📌 파일명: 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

서비스 확인

kubectl get svc -o wide

👉 서비스가 nginx-service로 정상적으로 생성


 (3) Ingress 리소스 생성 (HTTP 요청을 Nginx로 연결)

📌 파일명: nginx-ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
  - host: master
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx-service
            port:
              number: 80

📌 적용 명령어

kubectl apply -f nginx-ingress.yaml

Ingress 확인

kubectl get ingress

출력 예시

NAME            CLASS    HOSTS             ADDRESS   PORTS   AGE
nginx-ingress   <none>   master            192.168.98.162       80      41s

👉 http://192.168.98.162:80 도메인을 Ingress로 연결.

LIST