사전 작업
AWS에 쿠버네티스 설치
모니터링 터미널
watch -d 'kubectl get ns,no,po,svc,deploy,rs,ing,ep -o wide'
<1> WordPress와 MySQL 배포하기 15단계
<2> 삭제
<3> 참고 사이트
<1> WordPress와 MySQL 배포하기 15단계
1
다운로드1
wget https://kubernetes.io/examples/application/wordpress/mysql-deployment.yaml
ubuntu@ip-172-20-50-211:~$ more wordpress-deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
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: 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: wp-pv-claim
ubuntu@ip-172-20-50-211:~$
2
다운로드2
wget https://kubernetes.io/examples/application/wordpress/wordpress-deployment.yaml
ubuntu@ip-172-20-50-211:~$ more wordpress-deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
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: 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: wp-pv-claim
ubuntu@ip-172-20-50-211:~$ more wordpress-deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
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: 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: wp-pv-claim
ubuntu@ip-172-20-50-211:~$
3
ubuntu@ip-172-20-50-211:~$ ls
client.crt client.key mysql-deployment.yaml wordpress-deployment.yaml
4
cat <<EOF >./kustomization.yaml
> secretGenerator:
> - name: mysql-pass
> literals:
> - password=YOUR_PASSWORD
> EOF
5
암호변경
ubuntu@ip-172-20-50-211:~$ vi kustomization.yaml
ubuntu@ip-172-20-50-211:~$ more kustomization.yaml
secretGenerator:
- name: mysql-pass
literals:
- password=good11!!
6
추가
cat <<EOF >>./kustomization.yaml
> resources:
> - mysql-deployment.yaml
> - wordpress-deployment.yaml
> EOF
7
생성
kubectl apply -k ./
secret/mysql-pass-92m4hdbb29 created
service/wordpress-mysql created
service/wordpress created
deployment.apps/wordpress-mysql created
deployment.apps/wordpress created
persistentvolumeclaim/mysql-pv-claim created
persistentvolumeclaim/wp-pv-claim created
8
확인
kubectl get secrets
NAME TYPE DATA AGE
default-token-zkk9j kubernetes.io/service-account-token 3 2d16h
mysql-pass-92m4hdbb29 Opaque 1 7s
9
확인
kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysql-pv-claim Bound pvc-6e274cb5-f5d8-44a0-9ed9-5512576d3e28 20Gi RWO kops-ssd-1-17 14s
wp-pv-claim Bound pvc-c6e872bf-e92f-43b8-aa8f-56e53fcb1ae1 20Gi RWO kops-ssd-1-17 14s
10
pod 생성 확인 - 생성중
kubectl get pods
NAME READY STATUS RESTARTS AGE
wordpress-69bfd58568-qgn2v 0/1 ContainerCreating 0 21s
wordpress-mysql-559b5b779d-wls5b 0/1 ContainerCreating 0 21s
11
pod 생성확인 - 5분후 생성완료
kubectl get pods
NAME READY STATUS RESTARTS AGE
wordpress-69bfd58568-qgn2v 1/1 Running 0 74s
wordpress-mysql-559b5b779d-wls5b 1/1 Running 0 74s
ubuntu@ip-172-20-50-211:~$
12
서비스 확인
kubectl get services wordpress
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpress LoadBalancer 100.66.95.42 ad4f624b18bcb4a608feffd57e0453f3-757126102.ap-northeast-1.elb.amazonaws.com 80:30217/TCP 96s
13
dig +short ad4f624b18bcb4a608feffd57e0453f3-757126102.ap-northeast-1.elb.amazonaws.com
18.182.200.95
18.180.189.67
14
웹브라우저로 접속
15
watch -d 'kubectl get ns,no,po,svc,deploy,rs,ing,ep -o wide'
NAME STATUS AGE
namespace/default Active 2d16h
namespace/kube-node-lease Active 2d16h
namespace/kube-public Active 2d16h
namespace/kube-system Active 2d16h
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
node/ip-172-20-50-211.ap-northeast-1.compute.internal Ready control-plane,master 2d16h v1.20.8 172.20.50.211 18.179.205.221 Ubuntu 20.04.2 LTS 5.4.0-1047-aws containerd://1.4.4
node/ip-172-20-62-233.ap-northeast-1.compute.internal Ready node 2d16h v1.20.8 172.20.62.233 52.194.222.37 Ubuntu 20.04.2 LTS 5.4.0-1047-aws containerd://1.4.4
node/ip-172-20-63-189.ap-northeast-1.compute.internal Ready node 2d16h v1.20.8 172.20.63.189 13.115.147.25 Ubuntu 20.04.2 LTS 5.4.0-1047-aws containerd://1.4.4
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/wordpress-69bfd58568-qgn2v 1/1 Running 0 21m 100.98.83.3 ip-172-20-62-233.ap-northeast-1.compute.internal <none> <none>
pod/wordpress-mysql-559b5b779d-wls5b 1/1 Running 0 21m 100.98.83.2 ip-172-20-62-233.ap-northeast-1.compute.internal <none> <none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/kubernetes ClusterIP 100.64.0.1 <none> 443/TCP 2d16h <none>
service/wordpress LoadBalancer 100.66.95.42 ad4f624b18bcb4a608feffd57e0453f3-757126102.ap-northeast-1.elb.amazonaws.com 80:30217/TCP 21m app=wordpress,tier=frontend
service/wordpress-mysql ClusterIP None <none> 3306/TCP 21m app=wordpress,tier=mysql
<2> 삭제
1
kubectl delete pod --all
pod "wordpress-69bfd58568-qgn2v" deleted
pod "wordpress-mysql-559b5b779d-wls5b" deleted
2
kubectl delete deployments,svc,ingress --all
deployment.apps "wordpress" deleted
deployment.apps "wordpress-mysql" deleted
service "kubernetes" deleted
service "wordpress" deleted
service "wordpress-mysql" deleted
종료
https://kubernetes.io/ko/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/
전체 보기
https://brunch.co.kr/@topasvga/1656
감사합니다.