k8s實戰-搭建wordpress


1 部署NFS服務 做共享存儲

服務端:172.18.47.93

yum install nfs-utils -y

 編輯配置文件

[root@localhost ~]# vim /etc/exports
/nfs    172.18.47.0/16(rw,no_root_squash)

 開啟服務

[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl start nfs

 創建兩個目錄

[root@localhost nfs]# mkdir {mysql,nginx}
[root@localhost nfs]# ll
總用量 0
drwxr-xr-x. 2 root root 6 1月   7 15:18 mysql
drwxr-xr-x. 2 root root 6 1月   7 15:18 nginx

 

客戶端:172.18.47.90/91/92

yum install nfs-utils -y

 驗證是否可以訪問nfs服務端

[root@k8s-node1 ~]# showmount -e 172.18.47.93
Export list for 172.18.47.93:
/nfs 172.18.47.0/16

 2 創建pv

cat pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv
spec:
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteMany
  nfs:
    path: /nfs/mysql
    server: 172.18.47.93
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: wp-pv01
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  nfs: 
    path: /nfs/nginx
    server: 172.18.47.93
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: wp-pv02
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  nfs:
    path: /nfs/nginx
    server: 172.18.47.93

 

[root@k8s-master pv]# kubectl  apply -f pv.yaml 
persistentvolume/mysql-pv created
persistentvolume/wp-pv01 created
persistentvolume/wp-pv02 created

 3 部署mysql

創建mysql-deployment

cat mysql-deployment.yaml

apiVersion: v1
kind: Service
metadata:
  name: wordpress-mysql
  labels:
    app: wordpress
spec:
  ports:
    - port: 3306
  selector:
    app: wordpress
    tier: mysql
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
  labels: 
    app: wordpress
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 20Gi
---
apiVersion: apps/v1beta2
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:
      - name: mysql
    spec:
      containers:
      - name: mysql
        image: mysql:5.6
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - mountPath: "/var/lib/mysql"
          name: mysql-data
      volumes:
      - name: mysql-data
        persistentVolumeClaim:
          claimName: mysql-pv-claim

創建mysql容器

[root@k8s-master mysql]# kubectl apply -f mysql-deploy.yaml 
service/wordpress-mysql created
persistentvolumeclaim/mysql-pv-claim created
deployment.apps/wordpress-mysql created

 通過secret 創建mysql 秘密

[root@k8s-master ~]# kubectl create secret generic mysql-pass --from-literal=password=123456
secret/mysql-pass created

 4 上傳鏡像到harbor


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM