https://www.cnblogs.com/zoulixiang/p/9504324.html
vi mysql-rc.yaml
apiVersion: v1 kind: ReplicationController metadata: name: mysql-rc labels: name: mysql-rc spec: replicas: 1 selector: name: mysql-pod template: metadata: labels: name: mysql-pod spec: containers: - name: mysql image: mysql imagePullPolicy: IfNotPresent ports: - containerPort: 3306 env: - name: MYSQL_ROOT_PASSWORD value: "mysql"
vi mysql-svc.yaml
[root@k8s-master ~]# cat mysql-svc.yaml apiVersion: v1 kind: Service metadata: name: mysql-svc labels: name: mysql-svc spec: type: NodePort ports: - port: 3306 protocol: TCP targetPort: 3306 name: http nodePort: 33306 selector: name: mysql-pod[root@k8s-master ~]# kubectl create -f mysql-rc.yaml
replicationcontroller "mysql-rc" created
[root@k8s-master ~]# kubectl create -f mysql-svc.yaml
service "mysql-svc" created
[root@k8s-node01 ~]# docker exec -it bc1c0034fbf7 /bin/bash
mysql -h127.0.0.1 -uroot -pmysql
alter user 'root'@'%' identified with mysql_native_password by'root';
alter user 'root'@'%' identified by 'mysql';
设置好mysql后,可以远程连接node中的mysql,node的ip为192.168.1.196,映射的端口为33306,可以用navicat工具连接到这个myql。
文章转载自:https://www.cnblogs.com/zoulixiang/p/9910337.html