Horizontal = scale-out 파드의 개수를 늘려감.
root@master:~/metallb# kubectl delete -f metallb.yml
namespace "metallb-system" deleted
serviceaccount "controller" deleted
serviceaccount "speaker" deleted
clusterrole.rbac.authorization.k8s.io "metallb-system:controller
clusterrole.rbac.authorization.k8s.io "metallb-system:speaker" d
role.rbac.authorization.k8s.io "config-watcher" deleted
clusterrolebinding.rbac.authorization.k8s.io "metallb-system:con
clusterrolebinding.rbac.authorization.k8s.io "metallb-system:spe
rolebinding.rbac.authorization.k8s.io "config-watcher" deleted
daemonset.apps "speaker" deleted
deployment.apps "controller" deleted
root@master:~/metallb# ls
h-deploy.yml ip-deploy.yml metal-cm.yml metallb-native.yaml
root@master:~/metallb# kubectl apply -f metallb.yml
namespace/metallb-system created
serviceaccount/controller created
serviceaccount/speaker created
clusterrole.rbac.authorization.k8s.io/metallb-system:controller
clusterrole.rbac.authorization.k8s.io/metallb-system:speaker cre
role.rbac.authorization.k8s.io/config-watcher created
clusterrolebinding.rbac.authorization.k8s.io/metallb-system:cont
clusterrolebinding.rbac.authorization.k8s.io/metallb-system:spea
rolebinding.rbac.authorization.k8s.io/config-watcher created
Warning: spec.template.spec.nodeSelector[beta.kubernetes.io/os]:
daemonset.apps/speaker created
deployment.apps/controller created
root@master:~/metallb# kubectl apply -f metal-cm.yml
configmap/config created
root@master:~/metallb# kubectl get pod -n metallb-system
NAME READY STATUS RESTARTS AGE
controller-bbd47b575-6pbpw 1/1 Running 0 51s
speaker-f9whz 1/1 Running 0 51s
speaker-psjms 1/1 Running 0 51s
root@master:~/metallb# kubectl apply -f h-deploy.yml
deployment.apps/h-deploy created
service/h-svc created
root@master:~/metallb# kubectl get pod -n metallb-system
NAME READY STATUS RESTARTS AGE
controller-bbd47b575-6pbpw 1/1 Running 0 96s
h-deploy-7d9ff6f9bc-7x574 1/1 Running 0 23s
h-deploy-7d9ff6f9bc-tbcbz 1/1 Running 0 23s
speaker-f9whz 1/1 Running 0 96s
speaker-psjms 1/1 Running 0 96s
******
30 template:
31 metadata:
32 creationTimestamp: null
33 labels:
34 app: hnginx
35 spec:
36 containers:
37 - image: 192.168.0.195:5000/hnginx
38 imagePullPolicy: Always
39 name: hnginx
40 resources: # 이 부분 수정
41 requests:
42 cpu: "10m"
43 limits:
44 cpu: "50m"
45 terminationMessagePath: /dev/termination-log
46 terminationMessagePolicy: File
47 dnsPolicy: ClusterFirst
48 restartPolicy: Always
49 schedulerName: default-scheduler
50 securityContext: {}
51 terminationGracePeriodSeconds: 30
******
root@master:~/metallb# kubectl edit deploy h-deploy -n metallb-system
deployment.apps/h-deploy edited
Metric-Server Installation : https://github.com/kubernetes-sigs/metrics-server
root@master:~/metallb# wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
root@master:~/metallb# vi components.yaml
*****
132 spec:
133 containers:
134 - args: # 이 부분 부터 수정
135 - --kubelet-insecure-tls # 추가
136 - --cert-dir=/tmp
137 - --secure-port=4443138
138 - --kubelet-preferred-address-types=InternalIP # Internal IP 로 만 하겠다.
139 - --kubelet-use-node-status-port
140 - --metric-resolution=15s141 image: k8s.gcr.io/metrics-server/metrics-server:v0. 6.2
*****
<metric-server 실행>
root@master:~/metallb# kubectl apply -f components.yaml
serviceaccount/metrics-server created
<top : 자원관리자>
root@master:~/metallb# kubectl top pod -n metallb-system
NAME CPU(cores) MEMORY(bytes)
controller-bbd47b575-6pbpw 1m 25Mi
h-deploy-56b7f544cf-fm7dt 0m 3Mi
h-deploy-56b7f544cf-q5kfv 0m 2Mi
speaker-f9whz 1m 8Mi
speaker-psjms 1m 8Mi
# deploy 는 아직 아무도 접속을 안했기 때문에 CPU가 0
<언제 오토스케일링을 할 것인지 조건 걸어주기>
# 최소 1개의 파드를 띄울 것이고 CPU 사용량이 50%를 초과하면 , 최대 5개 까지 띄울 것이다.
root@master:~/metallb# kubectl autoscale deploy h-deploy --min=1 --max=5 --cpu-percent=50 -n metallb-system
horizontalpodautoscaler.autoscaling/h-deploy autoscaled
root@master:~/metallb# kubectl get hpa -n metallb-system
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
h-deploy Deployment/h-deploy 0%/50% 1 5 2 75s
<테스트를 위해 부하 (무한 루프)적용>
# 현재 서비스의 IP 숙지
root@master:~/metallb# kubectl get svc -n metallb-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
h-svc LoadBalancer 10.108.224.149 211.183.3.111 80:32525/TCP 40m
root@master:~/metallb# i=0;while true;do echo $((i++)) `curl --silent 211.183.3.111`;sleep 0.01;done
...
1444 h-deploy-56b7f544cf-8k7tx
1445 h-deploy-56b7f544cf-8k7tx
1446 h-deploy-56b7f544cf-8k7tx
1447 h-deploy-56b7f544cf-q5kfv
1448 h-deploy-56b7f544cf-8k7tx
1449 h-deploy-56b7f544cf-q5kfv
1450 h-deploy-56b7f544cf-q5kfv
1451 h-deploy-56b7f544cf-8k7tx
...
root@master:~# kubectl get hpa -n metallb-system
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
h-deploy Deployment/h-deploy 0%/50% 1 5 4 9m47s
p-deploy 는 파드 생성시 cpu를 노드의 2% 설정, 부하 발생시 최대 6%
파드의 cpu 사용량이 80% 이상일때 auto-scale 이 발생하도록 하시오.
단, 파드의 최소개수는 2, 최대 10개로 구성해볼 것.
root@master:~/metallb# i=0;while true;do echo $((i++)) `curl --silent 211.183.3.114`;sleep 0.01;done
root@master:~# kubectl get hpa -n metallb-system
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
h-deploy Deployment/h-deploy 0%/50% 1 5 1 40m
p-deploy Deployment/p-deploy 0%/80% 2 10 2 15m
<nfs 서버 설치>
root@master:~/metallb# apt-get -y install nfs-server
root@master:~/metallb# mkdir /pv
root@master:~/metallb# chmod 777 -R /pv
root@master:~/metallb# vi /etc/exports
<추가>
****
/pv *(rw,sync,no_root_squash)
# 전체 대상에게 읽고 쓰기 + 씽크 (동기화) + no root squash (루트 관리자 권한으로 서버에 접근 하여 읽기 쓰기 작업을 수행하겠다)
****
root@master:~/metallb# exportfs -r
<시작도 하고 enable 도 해중 --now 옵션>
root@master:~/metallb# systemctl --now enable nfs-server
root@master:~/metallb# systemctl status nfs-server | grep Active
Active: active (exited) since Fri 2023-01-13 03:10:06 UTC; 44s ago
<manifest 파일 만들기>
root@master:~/metallb# mkdir /vol
root@master:~/metallb# cd /vol/
root@master:/vol# vi pv.yml
*****
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
server: 211.183.3.100
path: /pv
readOnly: false
*****
storage : 용량
accessModes
1. ReadWriteMany : 여러 노드에서 읽고 쓰기 가능
2. ReadWriteOnce : 하나의 노드에서 읽고 쓰기 가능
3. ReadOnlyMany: 여러 노드에서 읽기만 가능
persistentVolumeReclaimPolicy : PV에 대한 재요청(주로 PVC 가 삭제 됐을때) 정책
1. Retain(유지) : PVC 가 삭제시 PV데이터 보존, released 상태가 되어 재요청(PVC)는 불가능
2. Recycle : PVC 가 삭제시 데이터는 사라지고 디렉토리 재요청(PVC) 가능.
3. Delete : PVC 식제시 디렉토리 자체가 삭제 - PV를 재생성 해야함.
root@master:/vol# kubectl apply -f pv.yml
persistentvolume/pv created
root@master:/vol# cp pv.yml pv-h.yml
root@master:/vol# cp pv.yml pv-ip.yml
root@master:/vol# kubectl delete -f pv.yml
persistentvolume "pv" deleted
root@master:/vol# cat pv-h.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-h# 이 부분 수정
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
server: 211.183.3.100
path: /pv/h# 이 부분 수정
readOnly: false
root@master:/vol# cat pv-ip.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-ip# 이 부분 수정
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
nfs:
server: 211.183.3.100
path: /pv/ip# 이 부분 수정
readOnly: false
<우분투에서는 worker 노드들에게 nfs-common 패키지가 있어야 한다>
<worker1>
root@worker1:~# apt-get -y install nfs-common
<worker2>
root@worker2:~# apt-get -y install nfs-common
<h에 대한 pvc 생성>
root@master:/vol# vi pvc-h.yml
root@master:/vol# cat pvc-h.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-h
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 500Mi
root@master:/vol# kubectl apply -f pvc-h.yml
persistentvolumeclaim/pvc-h created
root@master:/vol# kubectl apply -f pv-h.yml
persistentvolume/pv-h created
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Retain Bound default/pvc-h 9s
root@master:/vol# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-h Bound pv-h 1Gi RWX 2m1s
root@master:/vol# kubectl delete -f pvc-h.yml
persistentvolumeclaim "pvc-h" deleted
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Retain Released default/pvc-h 51s
root@master:/vol# kubectl apply -f pvc-h.yml
persistentvolumeclaim/pvc-h created
root@master:/vol# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-h Pending 6s
재요청 불가
root@master:/vol# kubectl delete -f pv-h.yml -f pvc-h.yml
persistentvolume "pv-h" deleted
persistentvolumeclaim "pvc-h" deleted
<Recycle 버전>
root@master:/vol# cat pv-h.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-h
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Recycle
nfs:
server: 211.183.3.100
path: /pv/h
readOnly: false
root@master:/vol# kubectl apply -f pv-h.yml
persistentvolume/pv-h created
root@master:/vol# kubectl apply -f pvc-h.yml
persistentvolumeclaim/pvc-h created
root@master:/vol# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-h Bound pv-h 1Gi RWX 33s
root@master:/vol# kubectl delete -f pvc-h.yml
persistentvolumeclaim "pvc-h" deleted
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Recycle Released default/pvc-h 91s
root@master:/vol# kubectl apply -f pvc-h.yml
persistentvolumeclaim/pvc-h created
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Recycle Released default/pvc-h 2m12s
root@master:/vol# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-h Pending 8s
<디렉토리를 생성안했기 때문에 원하는 결과가 안나오는 거임>
다시 삭제하고 다시 생성
root@master:/vol# kubectl delete -f pv-h.yml -f pvc-h.yml
persistentvolume "pv-h" deleted
persistentvolumeclaim "pvc-h" deleted
root@master:/vol# kubectl get pv
No resources found
root@master:/vol# kubectl get pvc
No resources found in default namespace.
root@master:/vol# mkdir -p /pv/h
root@master:/vol# mkdir -p /pv/ip
root@master:/vol# kubectl apply -f pv-h.yml -f pvc-h.yml
persistentvolume/pv-h created
persistentvolumeclaim/pvc-h created
root@master:/vol# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-h Bound pv-h 1Gi RWX 27s
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Recycle Bound default/pvc-h 28s
root@master:/vol# kubectl delete -f pvc-h.yml
persistentvolumeclaim "pvc-h" deleted
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Recycle Available 42s
root@master:/vol# kubectl get pvc
No resources found in default namespace.
root@master:/vol# kubectl apply -f pvc-h.yml
persistentvolumeclaim/pvc-h created
root@master:/vol# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-h Bound pv-h 1Gi RWX 3s
root@master:/vol# kubectl delete -f pvc-h.yml
persistentvolumeclaim "pvc-h" deleted
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Recycle Available 2m1s
<pvc, pv IP 생성>
******************************************************
root@master:/vol# ls
pvc-h.yml pv-h.yml pv-ip.yml pv.yml
root@master:/vol# cp pvc-h.yml pvc-ip.yml
root@master:/vol# vi pvc-ip.yml
root@master:/vol# cat pvc-ip.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-ip
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 500Mi
root@master:/vol# kubectl apply -f pv-ip.yml -f pvc-ip.yml
persistentvolume/pv-ip created
persistentvolumeclaim/pvc-ip created
root@master:/vol# kubectl delete -f pvc-ip.yml
persistentvolumeclaim "pvc-ip" deleted
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Recycle Available 5m44s
pv-ip 1Gi RWX Retain Available 50s
root@master:/vol# kubectl apply -f pvc-ip.yml
persistentvolumeclaim/pvc-ip created
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Recycle Bound default/pvc-ip 6m32s
pv-ip 1Gi RWX Retain Available 98s
root@master:/vol# cp pvc-ip.yml pvc-ip1.yml
root@master:/vol# vi pvc-ip1.yml
root@master:/vol# cat pvc-ip1.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-ip1
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 500Mi
root@master:/vol# kubectl apply -f pvc-ip1.yml
persistentvolumeclaim/pvc-ip1 created
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Recycle Bound default/pvc-ip 9m19s
pv-ip 1Gi RWX Retain Bound default/pvc-ip1 4m25s
root@master:/vol# kubectl delete -f pvc-ip1.yml
persistentvolumeclaim "pvc-ip1" deleted
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Recycle Bound default/pvc-ip 9m59s
pv-ip 1Gi RWX Retain Released default/pvc-ip1 5m5s
root@master:/vol# kubectl apply -f pvc-ip1.yml
persistentvolumeclaim/pvc-ip1 created
root@master:/vol# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-ip Bound pv-h 1Gi RWX 4m42s
pvc-ip1 Pending 10s
root@master:/vol# kubectl delete -f pvc-ip.yml -f pv-ip.yml -f pv-h.yml -f pvc-ip1.yml
persistentvolumeclaim "pvc-ip" deleted
persistentvolume "pv-ip" deleted
persistentvolume "pv-h" deleted
persistentvolumeclaim "pvc-ip1" deleted
root@master:/vol# kubectl get pv, pvc
error: arguments in resource/name form must have a single resource and name
root@master:/vol# kubectl apply -f pv-h.yml -f pvc-h.yml
persistentvolume/pv-h created
persistentvolumeclaim/pvc-h created
root@master:/vol# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-h 1Gi RWX Recycle Bound default/pvc-h 115s
root@master:/vol# cp ~/in/h-deploy.yml .
root@master:/vol# ls
h-deploy.yml pvc-ip1.yml pv-h.yml pv.yml
pvc-h.yml pvc-ip.yml pv-ip.yml
root@master:/vol# cat h-deploy.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: h-deploy
spec:
replicas: 2
selector:
matchLabels:
app: hnginx
template:
metadata:
labels:
app: hnginx
spec:
containers:
- name: hnginx
image: 192.168.0.195:5000/hnginx
volumeMounts:
- name: nfs-volume-h
mountPath: /mnt
volumes:
- name: nfs-volume-h
persistentVolumeClaim:
claimName: pvc-h
---
apiVersion: v1
kind: Service
metadata:
name: h-svc
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: hnginx
root@master:/vol# kubectl apply -f h-deploy.yml
deployment.apps/h-deploy created
service/h-svc unchanged
root@master:/vol# kubectl get pod
NAME READY STATUS RESTARTS AGE
h-deploy-74b444f5cb-4tgh5 1/1 Running 0 63s
h-deploy-74b444f5cb-d8p4r 1/1 Running 0 64s
<pod 안으로 들어가기>
root@master:/vol# kubectl exec -it h-deploy-74b444f5cb-4tgh5 -- /bin/bash
root@h-deploy-74b444f5cb-4tgh5:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
<mnt 디렉토리 들어가 있음>
root@h-deploy-74b444f5cb-4tgh5:/# touch /mnt/test.txt
root@h-deploy-74b444f5cb-4tgh5:/# exit
exit
root@master:~# cd metallb/
root@master:~/metallb# ls /pv/h/
test.txt
root@master:/vol# mkdir /wp
root@master:/vol# cd /wp
root@master:/wp# ls
root@master:/wp# clear
root@master:/wp# cat <<EOF >./kustomization.yaml
> secretGenerator:
> - name: mysql-pass
> literals:
> - password=YOUR_PASSWORD
> EOF
root@master:/wp# ls
kustomization.yaml
root@master:/wp# vi kustomization.yaml
root@master:/wp# cat kustomization.yaml
secretGenerator:
- name: mysql-pass
literals:
- password=YOUR_PASSWORD
<시크릿이 생성되면서 동시에 yml 파일이 apply 됨>
<wordpress , mysql .yml 다운>
root@master:/wp# wget https://k8s.io/examples/application/wordpress/wordpress-deployment.yaml
root@master:/wp# wget https://k8s.io/examples/application/wordpress/mysql-deployment.yaml
root@master:/wp# ls
kustomization.yaml mysql-deployment.yaml wordpress-deployment.yaml
root@master:/wp# cat kustomization.yaml
secretGenerator:
- name: mysql-pass
literals:
- password=YOUR_PASSWORD
resources:# 이 부분 추가
- mysql-deployment.yaml
- wordpress-deployment.yaml
<현재 디렉토리>
root@master:/wp# kubectl apply -k .
secret/mysql-pass-5m26tmdb5k created
service/wordpress created
service/wordpress-mysql created
persistentvolumeclaim/mysql-pv-claim created
persistentvolumeclaim/wp-pv-claim created
deployment.apps/wordpress created
deployment.apps/wordpress-mysql created
root@master:/wp# kubectl get pod
NAME READY STATUS RESTARTS AGE
wordpress-7fdfc976b9-5c2fd 0/1 Pending 0 49s
wordpress-mysql-6987d65455-4qwjc 0/1 Pending 0 49s
root@master:/wp# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4d3h
np-svc NodePort 10.110.210.139 <none> 80:30000/TCP 2d21h
wordpress LoadBalancer 10.104.33.58 211.183.3.111 80:32523/TCP 54s
wordpress-mysql ClusterIP None <none> 3306/TCP 54s
<pvc 는 pending 상태>
root@master:/wp# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysql-pv-claim Pending 4m34s
wp-pv-claim Pending 4m34s
풀이)
accessModes 를 pvc, pv 와 매칭시켜줘야 한다.
storage 크기를 적당히 크게 잡아줘야한다.
root@master:/wp# ls
kustomization.yaml wordpress-deployment.yaml
mysql-deployment.yaml
****
root@master:/wp# cat wordpress-deployment.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-wordpress
spec:
capacity:
storage: 25Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
server: 211.183.3.100
path: /pv/wordpress
readOnly: false
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: wordpress-volumeclaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 25Gi
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: frontend
spec:
containers:
- image: 192.168.0.195:5000/wordpress:4.8-apache
name: wordpress
env:
- name: WORDPRESS_DB_HOST
value: wordpress-mysql
- name: WORDPRESS_DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 80
name: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
volumes:
- name: wordpress-persistent-storage
persistentVolumeClaim:
claimName: wordpress-volumeclaim
****
****
root@master:/wp# cat mysql-deployment.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-mysql
spec:
capacity:
storage: 25Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
server: 211.183.3.100
path: /pv/mysql
readOnly: false
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mysql-volumeclaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 25Gi
---
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: mysql
spec:
containers:
- image: 192.168.0.195:5000/mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-volumeclaim
****
root@master:/wp# kubectl apply -k .
secret/mysql-pass-hg8bgc6f55 created
service/wordpress created
service/wordpress-mysql created
persistentvolume/pv-mysql created
persistentvolume/pv-wordpress created
persistentvolumeclaim/mysql-volumeclaim created
persistentvolumeclaim/wordpress-volumeclaim created
deployment.apps/wordpress created
deployment.apps/wordpress-mysql created
root@master:/wp# kubectl get pod
root@master:/wp# kubectl get pod
NAME READY STATUS RESTARTS AGE
wordpress-678b5ffbfd-xfd92 1/1 Running 0 47s
wordpress-mysql-69488bbc58-96xzn 1/1 Running 0 47s
root@master:/wp# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4d6h
np-svc NodePort 10.110.210.139 <none> 80:30000/TCP 3d
wordpress LoadBalancer 10.97.29.230 211.183.3.111 80:31375/TCP 56s
wordpress-mysql ClusterIP None <none> 3306/TCP 56s
root@master:/wp# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
mysql 25Gi RWO Retain Released default/wordpress-volumeclaim 82m
pv-mysql 25Gi RWO Recycle Bound default/mysql-volumeclaim 78s
pv-wordpress 25Gi RWO Recycle Bound default/wordpress-volumeclaim 78s
wordpress 25Gi RWO Retain Released default/mysql-volumeclaim 82m
root@master:/wp# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysql-pv-claim Pending 61m
mysql-volumeclaim Bound pv-mysql 25Gi RWO 82s
wordpress-volumeclaim Bound pv-wordpress 25Gi RWO 82s
wp-pv-claim Pending 61m
root@master:/wp# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP
kubernetes ClusterIP 10.96.0.1 <none>
np-svc NodePort 10.110.210.139 <none>
wordpress LoadBalancer 10.97.29.230 211.183.3.111
wordpress-mysql ClusterIP None <none>
root@master:~/metallb# vi components.yaml
*****
template:
metadata:
labels:
k8s-app: metrics-server
spec:
containers:
- args:
- --kubelet-insecure-tls
- --cert-dir=/tmp
- --secure-port=4443
- --kubelet-preferred-address-types=InternalIP,ExternalIP # 이 부분 설정
- --kubelet-use-node-status-port
- --metric-resolution=15s
image: k8s.gcr.io/metrics-server/metrics-server:v0.6.2
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
*****
root@master:~/metallb# kubectl apply -f components.yaml
root@master:~/metallb# kubectl edit deploy wordpress
deployment.apps/wordpress edited
*****
- containerPort: 80
name: wordpress
protocol: TCP
resources:
limits:
cpu: 50m
requests:
cpu: 10m
*****
root@master:~/metallb# kubectl autoscale deploy wordpress --min=1 --max=5 --cpu-percent=50
horizontalpodautoscaler.autoscaling/wordpress autoscaled
root@master:~# kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
wordpress Deployment/wordpress 10%/50% 1 5 5 5m31s