## Service apiVersion: v1 kind: Service metadata: name: mysql labels: app: mysql spec: type: NodePort ports: - name: mysql port: 3306 targetPort: 3306 nodePort: 30336 selector: app: mysql --- ## Deployment apiVersion: apps/v1 kind: Deployment metadata: name: mysql labels: app: mysql spec: replicas: 1 selector: matchLabels: app: mysql template: metadata: labels: app: mysql spec: containers: - name: mysql image: mysql:8.0.19 ports: - containerPort: 3306 env: - name: MYSQL_ROOT_PASSWORD ## 配置Root用户默认密码 value: "123456" resources: limits: cpu: 2000m memory: 512Mi requests: cpu: 2000m memory: 512Mi livenessProbe: initialDelaySeconds: 30 periodSeconds: 10 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 3 exec: command: ["mysqladmin", "-uroot", "-p${MYSQL_ROOT_PASSWORD}", "ping"] readinessProbe: initialDelaySeconds: 10 periodSeconds: 10 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 3 exec: command: ["mysqladmin", "-uroot", "-p${MYSQL_ROOT_PASSWORD}", "ping"] volumeMounts: - name: data mountPath: /var/lib/mysql - name: config mountPath: /etc/mysql/conf.d/my.cnf subPath: my.cnf - name: localtime readOnly: true mountPath: /etc/localtime volumes: - name: data persistentVolumeClaim: claimName: mysql - name: config configMap: name: mysql-config - name: localtime hostPath: type: File path: /etc/localtime