使用kubeadm搭建好kubernetes集群后就可以动手部署自己的应用了。
本文用例来自官网,如有需要请参看 kubernetes官网
一、环境说明
kubernetes 1.13.1
docker 18.06.1-ce
mysql 5.7
一、创建mysql-pv.yaml,用来将mysql存储的数据放到宿主机磁盘
kind: PersistentVolume apiVersion: v1 metadata: name: mysql-pv-volume labels: type: local spec: storageClassName: manual capacity: storage: 5Gi accessModes: - ReadWriteOnce hostPath: path: "/mnt/data" --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-pv-claim spec: storageClassName: manual accessModes: - ReadWriteOnce resources: requests: storage: 2Gi
二、创建mysql-deployment.yaml
apiVersion: v1 kind: Service metadata: name: mysql spec: ports: - port: 3306 selector: app: mysql clusterIP: None --- apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 kind: Deployment metadata: name: mysql spec: selector: matchLabels: app: mysql strategy: type: Recreate template: metadata: labels: app: mysql spec: containers: - image: mysql:5.7 name: mysql env: # Use secret in real usage - name: MYSQL_ROOT_PASSWORD value: uwaynemya ports: - containerPort: 3306 name: mysql volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql volumes: - name: mysql-persistent-storage persistentVolumeClaim: claimName: mysql-pv-claim
上述代码均可以在 haoprogrammer github 上找到
如果对您有帮助希望可以帮忙点颗星,感谢。
您的支持是我最大的动力!