ingrss 란 여러가지 조건에 따라 트래픽 라우팅을 설정해 주는 서비스이다.
AWS 로 예를들면 ALB 와 동일하다고 생각하면 된다.
설정할 수 있는 조건으로는 host 와 path 등이 있고, ingress 를 사용하기 위해서는 ingress-controller 가 설치 되어 있어야 한다.
예제
- Nginx Deployment 와 Service 가 Cluster 내부에서 기동 중
- ingress controller 를 사용하여 외부에서 내부의 Nginx 서비스로 접근
- Nginx ingress controller 는 아래의 경로를 통해 설치
https://kubernetes.github.io/ingress-nginx/deploy/#bare-metal-clusters
Installation Guide - Ingress-Nginx Controller
Installation Guide There are multiple ways to install the Ingress-Nginx 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
- Deploy, Service, Ingress 배포
- 배포 후 Nginx-ingress-controller 의 서비스 인 ingress-nginx-controller 의 ip:port 형식으로 호출하여야 한다
- ingress 에서 path 를 /test 로 설정하였으므로, 호출시 ip:port/test 를 하면 클러스터 내부의 nignx 응답을 받을 수 있다
---
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: nginx
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- image: nginx
name: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: nginx
name: nginx
spec:
ports:
- port: 31100
protocol: TCP
targetPort: 80
selector:
app: nginx
---
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /test
pathType: Prefix
backend:
service:
name: nginx
port:
number: 31100
- 제 횐경에서의 ingress-nginx-controller 는 30303 포트이므로 NodeIP:30303/test 를 하게되면 ingress 를 통해서 nignx 가 호출 된다
'k8s > CKAD' 카테고리의 다른 글
NetworkPolicy 개념 정리 (0) | 2024.01.20 |
---|---|
[CKAD] Secret 생성 후 Pod 에 env 로 사용 (0) | 2023.12.01 |
[CKAD]k8s Job / CronJob (0) | 2023.09.10 |
[CKAD]Docker image build (0) | 2023.09.09 |