본문 바로가기
kubernetes

Kubernetes Nginx Ingress Controller & Ingress 설치 및 구성

by aws-evan 2024. 12. 3.
반응형

 

 

 

  • Kubernetes ingress
    • 나의 IP로 여러 서비스 관리 가능
    • URL 기반으로 다른 서비스로 결 가능
    • SSL/TLS 인증서 한 곳에서 관

 

  • Kubernetes Ingress 흐름도

 

 

  • Nginx Ingress Controller 정보

https://github.com/kubernetes/ingress-nginx

 

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

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

github.com

 

  • Nginx Ingress Controller 지원 범위


1. Nginx Ingress Controller 

  • Nginx Ingress Controller  설치
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.12.0-beta.0/deploy/static/provider/cloud/deploy.yaml

 

  • Ingress Pod 정보
kubectl get pods -n ingress-nginx

 

  • IngressService 정보
kubectl get svc -n ingress-nginx

 


2. Deployment & Service

  • front Serivce
apiVersion: apps/v1
kind: Deployment
metadata:
  name: front
spec:
  replicas: 3
  selector:
    matchLabels:
      app: front
  template:
    metadata:
      name: front
      labels:
        app: front
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - name: http
          containerPort: 80
          protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: front
  labels:
    app: front
spec:
  type: ClusterIP
  ports:
  - name: http
    protocol: TCP
    port: 8080
    targetPort: 80
  selector:
    app: front

 

  • backend Service
apiVersion: apps/v1
kind: Deployment
metadata:
  name: fast
  labels:
    app: fast
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fast
  template:
    metadata:
      labels:
        app: fast
    spec:
      containers:
      - name: fast
        image: monta010/fastapi
        ports:
        - name: http
          containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: fast
  labels:
    app: fast
spec:
  type: ClusterIP
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
  selector:
    app: "fast"

 

 


3. Ingress 설정

  • Ingress Path Rule 설정
    • /front -> Service front 호출
    • /backend -> Service backend 호출
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: path
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /front
        pathType: Prefix
        backend:
          service:
            name: front
            port:
              name: http
  - http:
      paths:
      - path: /backend
        pathType: Prefix
        backend:
          service:
            name: backend
            port:
              name: http

 

 

  • /front 호출

 

 

  • backend 호출

반응형

'kubernetes' 카테고리의 다른 글

Kubernetes Containerd 데이터 경로 변경  (0) 2024.08.09
Kubernetes Containerd GPU 사용 방법  (0) 2024.08.09
Kubernetes CronJob  (0) 2024.07.05
Kubernetes Postgres DataBase Backup  (0) 2024.07.05
k3s 설치 가이드  (0) 2024.06.13

댓글