1、使用以下yaml即可

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    k8s-app: mysql1
    qcloud-app: mysql1
  name: mysql1
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: mysql1
      qcloud-app: mysql1
  serviceName: ""
  template:
    metadata:
      labels:
        k8s-app: mysql1
        qcloud-app: mysql1
    spec:
      containers:
      - env:
        - name: MYSQL_ROOT_PASSWORD
          value: "123456"
        image: mysql:5.7
        imagePullPolicy: Always
        name: mysql1
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 250m
            memory: 256Mi
        securityContext:
          privileged: false
		volumeMounts:
        - mountPath: /var/lib/mysql/
          name: data
      volumes:
      - hostPath:
          path: /mysql_data
        name: data
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: default
spec:
  ports:
  - name: 3306-3306-tcp
    nodePort: 31803
    port: 3306
    protocol: TCP
    targetPort: 3306
  selector:
    k8s-app: mysql
    qcloud-app: mysql
  type: NodePort
Logo

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

更多推荐