K8s:部署MySQL
部署mysql5.7
创建密码
echo -n "1125482715" | base64
mysql-secret.yml:
---
apiVersion: v1
kind: Secret
metadata:
name: mysql-secrets
type: Opaque
data:
ROOT_PASSWORD: MTEyNTQ4MjcxNQ==
kubectl apply -f mysql-secret.yml
kubectl get secret
kubectl describe secret mysql-secrets
创建持久化卷
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-data-disk
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100m
kubectl apply -f mysql-volume.yml
kubectl get persistentvolumeclaim
kubectl describe persistentvolumeclaim mysql-data-disk
部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deployment
labels:
app: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
ports:
- containerPort: 3306
volumeMounts:
- mountPath: "/var/lib/mysql"
subPath: "mysql"
name: mysql-data
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-secrets
key: ROOT_PASSWORD
volumes:
- name: mysql-data
persistentVolumeClaim:
claimName: mysql-data-disk
绑定IP
---
apiVersion: v1
kind: Service
metadata:
name: mysql-service
spec:
selector:
app: mysql
ports:
- protocol: TCP
port: 3306
targetPort: 3306