- Ingress Controller -> Ingress -> VM Port -> NodePort ( svc Port ) -> TargetPort ( Pod Port ) 순으로 연결된다
참고 ) p. 156
- MetalLB 를 통해 Ingress Controller 에 EXTERNAL-IP 를 부여할 것이다
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-nginx
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: default
port:
number: 80
- path: /shop
pathType: Prefix
backend:
service:
name: shop
port:
number: 80
- path: /blog
pathType: Prefix
backend:
service:
name: blog
port:
number: 80
- annotations 의 rewrite-target 은 실제 서비스 제공하는 포드의 기본 디렉토리로 이동해주는 옵션이다. / 라면, 기본 디렉토리로 간다
- number 는 svc 의 Port 이다
- Prefix 는 데이터 구분 타입이다
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.2/deploy/static/provider/cloud/deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: shop
spec:
replicas: 3
selector:
matchLabels:
app: shop
template:
metadata:
name: shop
labels:
app: shop
spec:
containers:
- name: shop
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: shop
spec:
ports:
- name: shop-port
port: 80 #service
targetPort: 80 #pod
nodePort: 30001 #worker node
selector:
app: shop
type: NodePort
apiVersion: apps/v1
kind: Deployment
metadata:
name: default
spec:
replicas: 3
selector:
matchLabels:
app: default
template:
metadata:
name: default
labels:
app: default
spec:
containers:
- name: default
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: default
spec:
ports:
- name: default-port
port: 80 #service
targetPort: 80 #pod
nodePort: 30000 #worker node
selector:
app: default
type: NodePort
apiVersion: apps/v1
kind: Deployment
metadata:
name: blog
spec:
replicas: 3
selector:
matchLabels:
app: blog
template:
metadata:
name: blog
labels:
app: blog
spec:
containers:
- name: blog
image: httpd
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: blog
spec:
ports:
- name: blog-port
port: 80 #service
targetPort: 80 #pod
nodePort: 30002 #worker node
selector:
app: blog
type: NodePort
- 구성이 비슷하므로 내용을 복사하여 sed 로 수정해도 된다
root@manager:~/k8slab/lab2# curl http://211.183.3.100:30000
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
root@manager:~/k8slab/lab2# curl http://211.183.3.100:30002
<html><body><h1>It works!</h1></body></html>
잘 동작한다
/ - default - Pod : 10 ~ 15 0.25/16m
/blog - blod - Pod : 5 ~ 10 0.25/16m
/shop - shop - Pod : 10 ~ 20 0.5/32m
test.com -> zone file 파일 -> test.com.db 에 등록해야 한다
도메인이 test.com 일 때, hong IN A 211.183.3.201 로 등록하면 hong.test.com 에 접속시 211.183.3.201 에 접속된다