先使用命令创建命名空间
kubectl create ns database
dep.yaml
--- apiVersion: apps/v1 kind: Deployment metadata: name: mysql-dep namespace: database labels: app: mysql spec: replicas: 1 selector: matchLabels: app: mysql template: metadata: labels: app: mysql spec: terminationGracePeriodSeconds: 40 containers: - name: mysql-images image: mysql:5.6 imagePullPolicy: IfNotPresent env: - name: MYSQL_ROOT_PASSWORD value: "123456" ports: - containerPort: 3306 name: app-port protocol: TCP resources: limits: cpu: 500m memory: 1Gi requests: cpu: 300m memory: 1Gi volumeMounts: - name: mysql-data mountPath: /var/lib/mysql - name: mysql-time mountPath: /etc/localtime volumes: - name: mysql-data persistentVolumeClaim: claimName: mysql-pvc - name: mysql-time hostPath: path: /etc/localtime
svc.yaml
--- apiVersion: v1 kind: Service metadata: name: mysql-svc namespace: database labels: app: mysql spec: selector: app: mysql type: NodePort ports: - name: database port: 3306 targetPort: app-port nodePort: 31006
pvc.yaml
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-pvc namespace: database spec: accessModes: - ReadWriteMany resources: requests: storage: 10Gi
我这里是动态的存储,创建pvc出来会自动绑定pv,具体部署可参考http://www.yepblog.cn/?p=297