-
[k8s] 워드프레스 구축클라우드/kubernetes 2021. 3. 16. 22:34728x90
master 192.168.122.11
node1 192.168.122.21
node2 192.168.122.22
node3 192.168.122.23
1. pod 생성해서 워드프레스 구축하기
pod-wordpress.yml
apiVersion: v1 kind: Pod metadata: name: pod-word labels: app: pod-word spec: containers: - name: pod-word image: wordpress:latest env: - name: WORDPRESS_DB_HOST value: "svc-head-db" - name: WORDPRESS_DB_USER value: "wp-admin" - name: WORDPRESS_DB_PASSWORD value: "1234" - name: WORDPRESS_DB_NAME value: "wordpress" volumeMounts: - name: word-vol mountPath: /var/www/html ports: - containerPort: 80 volumes: - name: word-vol persistentVolumeClaim: claimName: pvc-word
pod-db.yml
apiVersion: v1 kind: Pod metadata: name: pod-db labels: app: pod-db spec: containers: - image: mysql:5.7 name: pod-db env: - name: MYSQL_ROOT_PASSWORD value: "1234" - name: MYSQL_DATABASE value: "wordpress" - name: MYSQL_USER value: "wp-admin" - name: MYSQL_PASSWORD value: "1234" volumeMounts: - name: pod-db-vol mountPath: /var/lib/mysql subPath: mysql ports: - containerPort: 3306 protocol: TCP volumes: - name: pod-db-vol persistentVolumeClaim: claimName: pvc-db
svc-lb-word.yml
apiVersion: v1 kind: Service metadata: name: svc-lb-word spec: type: LoadBalancer ports: - port: 80 targetPort: 80 selector: app: pod-word
svc-headless-db.yml
apiVersion: v1 kind: Service metadata: name: svc-head-db spec: clusterIP: None ports: - port: 3306 targetPort: 3306 selector: app: pod-db
pvc-word.yml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-word spec: accessModes: - ReadWriteMany resources: requests: storage: 1Gi storageClassName: csi-cephfs
pvc-db.yml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-db spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi storageClassName: rook-ceph-block
$ kubectl create -f svc-lb-word.yml -f svc-headless-db.yml $ kubectl create -f pvc-word.yml -f pvc-db.yml $ kubectl create -f pod-wordpress.yml -f pod-db.yml $ kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.233.0.1 <none> 443/TCP 253d svc-head-db ClusterIP None <none> 3306/TCP 26m svc-lb-word LoadBalancer 10.233.44.252 192.168.122.200 80:31693/TCP 26m $ kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-6d805d55-2e8f-46cd-a3b9-18386055567e 1Gi RWX Delete Bound default/pvc-word csi-cephfs 18m pvc-aea9b252-4127-4747-9c82-936e80c7ac42 1Gi RWO Delete Bound default/pvc-db rook-ceph-block 18m $ kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE pvc-db Bound pvc-aea9b252-4127-4747-9c82-936e80c7ac42 1Gi RWO rook-ceph-block 21m pvc-word Bound pvc-6d805d55-2e8f-46cd-a3b9-18386055567e 1Gi RWX csi-cephfs 21m $ kubectl get pod NAME READY STATUS RESTARTS AGE pod/pod-db 1/1 Running 0 21m pod/pod-word 1/1 Running 0 16m
*! pod-wordpress.yml 워드프레스 파드에서 env 환경변수 부분은 주석처리 해준 후 생성 -> 주석처리 해체 후 다시 생성
apiVersion: v1 kind: Pod metadata: name: pod-word labels: app: pod-word spec: containers: - name: pod-word image: wordpress:latest #env: #- name: WORDPRESS_DB_HOST # value: "svc-head-db" #- name: WORDPRESS_DB_USER # value: "wp-admin" #- name: WORDPRESS_DB_PASSWORD # value: "1234" #- name: WORDPRESS_DB_NAME # value: "wordpress" volumeMounts: - name: word-vol mountPath: /var/www/html ports: - containerPort: 80 volumes: - name: word-vol persistentVolumeClaim: claimName: pvc-word
2. ReplicaSet 으로 워드프레스 구축하기
rs-wordpress.yml
apiVersion: apps/v1 kind: ReplicaSet metadata: name: pod-word spec: replicas: 2 selector: matchLabels: app: pod-word template: metadata: labels: app: pod-word spec: containers: - image: wordpress name: pod-wordpress env: - name: WORDPRESS_DB_HOST value: "db" name: WORDPRESS_DB_USER value: "admin" name: WORDPRESS_DB_PASSWORD value: "1234" name: WORDPRESS_DB_NAME value: "wordpress" volumeMounts: - name: pod-word-vol mountPath: /var/www/html ports: - containerPort: 80 protocol: TCP volumes: - name: pod-word-vol persistentVolumeClaim: claimName: pvc-word
rs-db.yml
apiVersion: apps/v1 kind: ReplicaSet metadata: name: pod-db labels: app: pod-db spec: replicas: 2 selector: matchLabels: app: pod-db template: metadata: labels: app: pod-db spec: containers: - image: mysql:5.7 name: pod-db env: - name: MYSQL_ROOT_PASSWORD value: "1234" name: MYSQL_DATABASE value: "wordpress" name: MYSQL_USER value: "admin" name: MYSQL_PASSWORD value: "1234" volumeMounts: - name: pod-db-vol mountPath: /var/lib/mysql subPath: mysql ports: - containerPort: 3306 protocol: TCP volumes: - name: pod-db-vol persistentVolumeClaim: claimName: pvc-db
'클라우드 > kubernetes' 카테고리의 다른 글
[k8s] 동적 볼륨 프로비저닝 (0) 2021.03.30 [k8s] 인그레스(Ingress) 컨트롤러 (0) 2021.03.30