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

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐