반응형
ingress-controller 설치하기
ingress-controller 설치
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.7.1/deploy/static/provider/aws/deploy.yaml
ingress-controller 설치 확인
$ kubectl get all -n ingress-nginx
ingress-controller 설정 확인하기
ingress-controller pod name 확인
$ kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
ingress-nginx-admission-create-bnq6h 0/1 Completed 0 44m
ingress-nginx-admission-patch-tbktp 0/1 Completed 1 44m
ingress-nginx-controller-78cd9ffdfc-nd9x8 1/1 Running 0 44m
ingress-controller pod 접속
$ kubectl exec -it -n ingress-nginx ingress-nginx-controller-78cd9ffdfc-nd9x8 -- bash
nginx.conf 설정 확인
$ cat /etc/nginx/nginx.conf
기본 예제
ingress-basic.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: demo-ingress
spec:
ingressClassName: nginx
rules:
- host: demo.ingress.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello-app-service
port:
number: 8080
---
apiVersion: v1
kind: Service
metadata:
name: hello-app-service
spec:
type: ClusterIP
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 8080
selector:
app: hello-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-app-deploy
spec:
replicas: 1
selector:
matchLabels:
app: hello-app
template:
metadata:
labels:
app: hello-app
spec:
containers:
- name: hello-app-container
image: gcr.io/google-samples/hello-app:1.0
ports:
- containerPort: 8080
실행
$ kubectl apply -f ingress-basic.yml
ingress 확인
$ kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
demo-ingress nginx demo.ingress.com localhost 80 2m36s
요청
$ curl demo.ingress.com
Hello, world!
Version: 1.0.0
Hostname: hello-app-deploy-6d8d4ff7f6-6ptwj
ingress proxy 예제
ingress-proxy.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: demo-ingress
annotations:
nginx.ingress.kubernetes.io/server-snippet: |
location /todos {
proxy_pass https://dummyjson.com;
proxy_http_version 1.1;
}
spec:
ingressClassName: nginx
rules:
- host: demo.ingress.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello-app-service
port:
number: 8080
---
apiVersion: v1
kind: Service
metadata:
name: hello-app-service
spec:
type: ClusterIP
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 8080
selector:
app: hello-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-app-deploy
spec:
replicas: 1
selector:
matchLabels:
app: hello-app
template:
metadata:
labels:
app: hello-app
spec:
containers:
- name: hello-app-container
image: gcr.io/google-samples/hello-app:1.0
ports:
- containerPort: 8080
실행
$ kubectl apply -f ingress-proxy.yml
요청
$ curl demo.ingress.com
Hello, world!
Version: 1.0.0
Hostname: hello-app-deploy-6d8d4ff7f6-r4g5g
$ curl demo.ingress.com/todos/1
{"id":1,"todo":"Do something nice for someone I care about","completed":true,"userId":26}
반응형
'Development > Kubernetes' 카테고리의 다른 글
[Kubernetes] kind(Kubernetes in Docker) 설치 (0) | 2023.11.13 |
---|---|
[Kubernetes] Helm Templates (0) | 2020.12.29 |
[Kubernetes] Helm 설치 (0) | 2020.12.29 |
[Kubernetes] Service (0) | 2020.12.29 |
[Kubernetes] 예제 (0) | 2020.12.29 |