k8s部署mysql
vim mysql.ymlapiVersion: v1kind: Namespacemetadata:name: lamp-cloud-k8s---apiVersion: v1kind: Deploymentmetadata:name: mysqlnamespace: lamp-cloud-k8slabels:name: mysqlspec:replicas: 1selector:name: my
·
vim mysql.yml
apiVersion: v1
kind: Namespace
metadata:
name: lamp-cloud-k8s
---
apiVersion: v1
kind: Deployment
metadata:
name: mysql
namespace: lamp-cloud-k8s
labels:
name: mysql
spec:
replicas: 1
selector:
name: mysql
template:
metadata:
labels:
name: mysql
spec:
containers:
- name: mysql
image: mysql
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "root"
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql #MySQL容器的数据都是存在这个目录的,要对这个目录做数据持久化
volumes:
- name: mysql-persistent-storage
hostPath:
path: /data/lamp-cloud-k8s/mysql-data
type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: lamp-cloud-k8s
labels:
name: mysql
spec:
type: NodePort
ports:
- port: 3306
protocol: TCP
targetPort: 3306
name: mysql
nodePort: 30306
selector:
name: mysql
查看mysql的pod
kubectl get pod -n lamp-cloud-k8s -o wide | grep mysql
mysql-7794b78dc6-b4xzp 1/1 Running 0 6m44s 10.244.0.10 master <none> <none>
进入pod
kubectl exec -it -n lamp-cloud-k8s mysql-7794b78dc6-b4xzp /bin/bash
进入mysql
mysql -uroot -p
配置mysql远程访问和密码
alter user 'root'@'%' identified with mysql_native_password by'o89m41w9hkyvoze3d5t4';
或者
alter user 'root'@'%' identified by 'o89m41w9hkyvoze3d5t4';
更多推荐
已为社区贡献2条内容
所有评论(0)