k8s部署mysql
作者:互联网
第一章
部署K8S集群
https://www.cnblogs.com/zoulixiang/p/9504324.html
第二章
1.新建mysql-rc.yaml
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"
2.创建mysql-svc.yaml
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-pod3.k8s 执行文件,下载mysql镜像和运行mysqlr容器
[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
第三章
1.登陆到mysql中, 在node01节点登陆
[root@k8s-node01 ~]# docker exec -it bc1c0034fbf7 /bin/bash
2.在容器内登录mysql。执行以下命令,-h为ip,容器内ip为127.0.0.1,-r为用户名,-p为密码,在mysql-rc中设置的密码。
mysql -h127.0.0.1 -uroot -pmysql
3、对mysql进行如下设置。
alter user 'root'@'%' identified with mysql_native_password by'root';
alter user 'root'@'%' identified by 'mysql';
4、退出mysql和容器,执行quit;退出mysql,按ctrl+p后,再按ctrl+q从容器中返回node主机。
设置好mysql后,可以远程连接node中的mysql,node的ip为192.168.1.196,映射的端口为33306,可以用navicat工具连接到这个myql。
文章转载自:https://www.cnblogs.com/zoulixiang/p/9910337.html
标签:name,部署,mysql,svc,rc,k8s,root 来源: https://www.cnblogs.com/rerise/p/16085719.html