Kubernetes Mysql系列|k8s部署mysql (deployment)
【代码】Kubernetes Mysql系列|mysql部署。
·
mysql.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /path/to/mysql-data
type: DirectoryOrCreate
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deployment
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
nodeName: k8s-node1
containers:
- name: mysql
image: mysql:8.0.28
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "1qaz@wsx"
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
---
apiVersion: v1
kind: Service
metadata:
name: my-db
spec:
ports:
- port: 3306
targetPort: 3306
nodePort: 30306
selector:
app: mysql
type: NodePort
kubectl get po,svc |grep mysql
更多推荐
已为社区贡献11条内容
所有评论(0)