样例文件如下所示:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: mysql
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- env:
- name: MYSQL_ROOT_PASSWORD
value: '123456'
image: 'mysql:oracle'
name: mysql
ports:
- containerPort: 3306
hostPort: 3306
resources:
limits:
cpu: "0.5"
requests:
cpu: "0.5"
volumeMounts:
- mountPath: /var/lib/mysql
name: volv
volumes:
- hostPath:
path: /Users/mac/Desktop/computer/A/k8s/data/mysql/var/lib/mysql
type: DirectoryOrCreate
name: volv
---
apiVersion: v1
kind: Service
metadata:
labels:
app: mysql
name: mysql
spec:
ports:
- port: 3306
protocol: TCP
targetPort: 3306
nodePort: 30006
selector:
app: mysql
type: LoadBalancer
K8S运行MySQL的yaml配置1, kubernetes3