선결조건
(상태 확인, 마운트 가능여부 확인을 위해, node에서 showmount -e 211.183.3.100)
시나리오
metallb 있는 지 확인
kubectl get ns
kubectl get pod -n metallb-system
nfs 동작 확인
systemctl status nfs-server | grep Active
mkdir /kia /sk
chmod 777 /sk -R
chmod 777 /kia -R
vi /etc/exports
/kia 211.183.3.0/24(rw,no_root_squash,sync)
/sk 211.183.3.0/24(rw,no_root_squash,sync)
systemctl restart nfs-server
worker에서 확인
showmount -e 211.183.3.100
kubectl api-resource | grep Namespace 로 버전 확인 가능
명령으로 할거면→ kubectl create ns sk ; kubectl create ns kia
yaml로 할거면
apiVersion: v1
kind: Namespace
metadata:
name: kia
kubectl apply -f kia-ns.yaml
kubectl get ns | grep kia
apiVersion: v1
kind: Namespace
metadata:
name: sk
kubectl apply -f sk-ns.yaml
kubectl get ns | grep sk
default : 211.183.3.201 - 211.183.3.210
kia : 211.183.3.211 - 211.183.3.220
sk : 211.183.3.221 - 211.183.3.230
metallb + configmap
lb-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: | # 이게 없다면 그대로 찍어내지 못하게 됨i
address-pools:
- name: default
protocol: layer2
addresses:
- 211.183.3.201-211.183.3.210
- name: kia
protocol: layer2
addresses:
- 211.183.3.211-211.183.3.220
- name: sk
protocol: layer2
addresses:
- 211.183.3.221-211.183.3.230
root@manager:~/k8slab/lab1# kubectl apply -f lb-config.yaml
configmap/config created
참고 : https://metallb.universe.tf/usage/
kia-deploy-svc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: kia
name: kia-deploy
spec: # RS
strategy:
type: Recreate
replicas: 3
selector:
matchLabels:
app: kia
template: # POD
metadata:
labels:
app: kia
spec: # container
containers:
- name: kia-nginx
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
namespace: kia
name: kia-lb
annotations:
metallb.universe.tf/address-pool: kia
spec:
ports:
- port: 80
targetPort: 80
selector:
app: kia
type: LoadBalancer
root@manager:~/k8slab/lab1# kubectl apply -f kia-deploy-svc.yaml
deployment.apps/kia-deploy created
root@manager:~/k8slab/lab1# kubectl get pod,svc -n kia
NAME READY STATUS RESTARTS AGE
pod/kia-deploy-5fcb8b68db-jll9t 1/1 Running 0 46s
pod/kia-deploy-5fcb8b68db-mph28 1/1 Running 0 46s
pod/kia-deploy-5fcb8b68db-rdj9d 1/1 Running 0 46s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kia-lb LoadBalancer 10.110.41.95 211.183.3.211 80:31261/TCP 46s
sk-deploy-svc.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: sk
name: sk-deploy
spec: # RS
strategy:
type: Recreate
replicas: 3
selector:
matchLabels:
app: sk
template: # POD
metadata:
labels:
app: sk
spec: # container
containers:
- name: sk-nginx
image: httpd
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
namespace: sk
name: sk-lb
annotations:
metallb.universe.tf/address-pool: sk
spec:
ports:
- port: 80
targetPort: 80
selector:
app: sk
type: LoadBalancer
root@manager:~/k8slab/lab1# kubectl apply -f sk-deploy-svc.yaml
deployment.apps/sk-deploy created
root@manager:~/k8slab/lab1# kubectl get pod,svc -n sk
NAME READY STATUS RESTARTS AGE
pod/sk-deploy-848bb96648-2l9mx 1/1 Running 0 39s
pod/sk-deploy-848bb96648-4gbm4 1/1 Running 0 39s
pod/sk-deploy-848bb96648-ff44z 1/1 Running 0 39s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/sk-lb LoadBalancer 10.103.144.31 211.183.3.221 80:30256/TCP 39s
root@manager:~/k8slab/lab1# touch /kia/kia.txt
root@manager:~/k8slab/lab1# touch /sk/sk.txt
확인 해야 할 사항
kubectl exec [pod이름] -n [ns이름:kia,sk] -- ls /test
-n kia면 kia.txt가, -n sk면 sk.txt가 들어 있어야 한다.
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: kia
name: kia-deploy
spec: # RS
strategy:
type: Recreate
replicas: 3
selector:
matchLabels:
app: kia
template: # POD
metadata:
labels:
app: kia
spec: # container
containers:
- name: kia-nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: kia-volume
mountPath: /test
volumes:
- name: kia-volume
nfs:
path: /kia
server: 211.183.3.100
---
apiVersion: v1
kind: Service
metadata:
namespace: kia
name: kia-lb
annotations:
metallb.universe.tf/address-pool: kia
spec:
ports:
- port: 80
targetPort: 80
selector:
app: kia
type: LoadBalancer
root@manager:~/k8slab/lab1# kubectl exec pod/kia-deploy-5dd76667dc-225s9 -n kia -- ls /test
kia.txt
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: kia
name: kia-deploy
spec: # RS
strategy:
type: Recreate
replicas: 3
selector:
matchLabels:
app: kia
template: # POD
metadata:
labels:
app: kia
spec: # container
containers:
- name: kia-nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: kia-volume
mountPath: /test
volumes:
- name: kia-volume
nfs:
path: /kia
server: 211.183.3.100
---
apiVersion: v1
kind: Service
metadata:
namespace: kia
name: kia-lb
annotations:
metallb.universe.tf/address-pool: kia
spec:
ports:
- port: 80
targetPort: 80
selector:
app: kia
type: LoadBalancer
loadBalancerIP: 211.183.3.215 #로드밸런서 IP 지정할 수도 있음
root@manager:~/k8slab/lab1# kubectl get pod,svc -n kia
NAME READY STATUS RESTARTS AGE
pod/kia-deploy-5dd76667dc-225s9 1/1 Running 0 115m
pod/kia-deploy-5dd76667dc-f5sm8 1/1 Running 0 115m
pod/kia-deploy-5dd76667dc-sqvdn 1/1 Running 0 115m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kia-lb LoadBalancer 10.110.41.95 211.183.3.215 80:31261/TCP 146m
시작하면
worker부터 실행 → master 실행
kubectl get no
kubectl get pod -n kube-system (calico, api/scheduler/controller)
kubectl get pod -n metallb-system (controller, speaker)
위의 명령 실행이 되지 않는다면 현재 계정은 kubernetes 환경에 대한 SA 가 없는 상태.