- 단, 이번에는 L2 로 이용
- 외부로의 접속은 MetalLB 를 이용한다. 단, LB 에 제공하는 주소 대역은 211.183.3.231 ~ 211.183.3.249 이다
- Deployment 는 3 개의 nginx 를 이용한 웹 서비스를 제공하며, Pod 는 각각 0.5 CPU, 32MB 메모리가 기본적으로 제공된다. Pod 는 기본적으로 3 개 제공한다
- 만약, 각 Pod 의 Cpu 사용량이 80 % 를 넘어서게 되면, 최대 10 개 까지 확장 가능해야 한다
- nginx 의 페이지는 Ingress 를 통해 라우팅 되어야 한다. 이는 nginx ingress controller 를 이용하여 다음과 같이 구성한다
LB 를 통해 Ingress Controller 에 들어온 다음, / - default , /shop - shop , /news - news 로 연결한다. 각각 NodePort 서비스이며, 순서대로 30001, 30002, 30003 으로 한다
/ 는 /default, /shop 은 /shop, /news 는 /news 디렉토리 사용
kubeadm init --apiserver-advertise-address 211.183.3.100
- Join 한 Node 의 상태를 확인하자
docker login
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml # yaml 파일로 calico 배포
root@manager:~/k8slab# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-867d8d6bd8-wb2h5 0/1 Pending 0 9s
calico-node-jm5vq 0/1 Init:0/3 0 9s
calico-node-nzpvr 0/1 Init:0/3 0 9s
calico-node-zkrjk 0/1 Init:0/3 0 9s
coredns-558bd4d5db-k5w72 0/1 Pending 0 12m
coredns-558bd4d5db-q47vn 0/1 Pending 0 12m
etcd-manager 1/1 Running 0 12m
kube-apiserver-manager 1/1 Running 0 12m
kube-controller-manager-manager 1/1 Running 0 12m
kube-proxy-kglb9 1/1 Running 0 4m57s
kube-proxy-nc22d 1/1 Running 0 12m
kube-proxy-x6xxs 1/1 Running 0 5m
kube-scheduler-manager 1/1 Running 0 12m
apt install -y nfs-server # master 에 서버 설치
apt install -y nfs-common # worker 에 Client 설치
root@manager:~/k8slab/rapalab# cat /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/root/k8slab/rapalab/default 211.183.3.0/24(rw,no_root_squash,sync)
/root/k8slab/rapalab/shop 211.183.3.0/24(rw,no_root_squash,sync)
/root/k8slab/rapalab/news 211.183.3.0/24(rw,no_root_squash,sync)
apiVersion: v1
kind: Namespace
metadata:
name: rapa
kubectl create ns metallb-system
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 211.183.3.231-211.183.3.249
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: rapa
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: /news
pathType: Prefix
backend:
service:
name: news
port:
number: 80
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: default
namespace: rapa
spec:
replicas: 3
selector:
matchLabels:
app: default
template:
metadata:
name: default
labels:
app: default
spec:
containers:
- name: default
image: nginx
ports:
- containerPort: 80
resources:
requests:
cpu: 500m
memory: 32Mi
volumeMounts:
- name: default-vol
mountPath: /usr/share/nginx/html
volumes:
- name: default-vol
nfs:
path: /root/k8slab/rapalab/default
server: 211.183.3.100
---
apiVersion: v1
kind: Service
metadata:
namespace: rapa
name: default
spec:
ports:
- name: default-port
port: 80 #service
targetPort: 80 #pod
nodePort: 30001 #worker node
selector:
app: default
type: NodePort
apiVersion: apps/v1
kind: Deployment
metadata:
name: shop
namespace: rapa
spec:
replicas: 3
selector:
matchLabels:
app: shop
template:
metadata:
name: shop
labels:
app: shop
spec:
containers:
- name: shop
image: nginx
ports:
- containerPort: 80
resources:
requests:
cpu: 500m
memory: 32Mi
volumeMounts:
- name: shop-vol
mountPath: /usr/share/nginx/html
volumes:
- name: shop-vol
nfs:
path: /root/k8slab/rapalab/shop
server: 211.183.3.100
---
apiVersion: v1
kind: Service
metadata:
namespace: rapa
name: shop
spec:
ports:
- name: shop-port
port: 80 #service
targetPort: 80 #pod
nodePort: 30003 #worker node
selector:
app: shop
type: NodePort
apiVersion: apps/v1
kind: Deployment
metadata:
name: news
namespace: rapa
spec:
replicas: 3
selector:
matchLabels:
app: news
template:
metadata:
name: news
labels:
app: news
spec:
containers:
- name: news
image: nginx
ports:
- containerPort: 80
resources:
requests:
cpu: 500m
memory: 32Mi
volumeMounts:
- name: news-vol
mountPath: /usr/share/nginx/html
volumes:
- name: news-vol
nfs:
path: /root/k8slab/rapalab/news
server: 211.183.3.100
---
apiVersion: v1
kind: Service
metadata:
namespace: rapa
name: news
spec:
ports:
- name: news-port
port: 80 #service
targetPort: 80 #pod
nodePort: 30002 #worker node
selector:
app: news
type: NodePort
wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
root@manager:~/k8slab/rapalab# k autoscale deploy default -n rapa --cpu-percent=80 --min=3 --max=10
horizontalpodautoscaler.autoscaling/default autoscaled
root@manager:~/k8slab/rapalab# k autoscale deploy shop -n rapa --cpu-percent=80 --min=3 --max=10
horizontalpodautoscaler.autoscaling/shop autoscaled
root@manager:~/k8slab/rapalab# k autoscale deploy news -n rapa --cpu-percent=80 --min=3 --max=10
horizontalpodautoscaler.autoscaling/news autoscaled
root@manager:~/k8slab/rapalab# cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 manager
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
211.183.3.100 manager manager.rapa.pri
211.183.3.101 worker1 worker1.rapa.pri
211.183.3.102 worker2 worker2.rapa.pri
211.183.3.103 worker3 worker3.rapa.pri
211.183.3.231 www.jaehong.com
- 해당 페이지의 html 내용을 잘 가져온다
- /, /shop, /news 접속시 Ingress 를 통해 각각의 NodePort Service 에 연결되어 Pod 의 서비스가 잘 제공된다
- NFS 를 통해 지정한 index.html 이 잘 출력된다
- master Node 의 브라우저에서는 hosts 에 등록한 주소로 접속이 가능하다
- 다른 페이지도 모두 잘 접속된다
apt install -y apache2-utils
ab -c 1000 -n 200 -t 60 http://211.183.3.231/
ab -c 1000 -n 200 -t 60 http://211.183.3.231/shop/
ab -c 1000 -n 200 -t 60 http://211.183.3.231/news/