路大师_XA

K8S安装MySQL

2021-12-06  本文已影响0人  墨迹嘿嘿
我们先建立yaml文件 mysql-rc.yaml 和 mysql-svc.yaml image

新建mysql-rc.yaml

vi mysql-rc.yaml
image

复制可得:

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"

新建mysql-svc.yaml

vi mysql-svc.yaml
image

复制可得

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: 32306
  selector:
    name: mysql-pod

k8s 执行文件,下载mysql镜像和运行mysqlr容器

kubectl create -f mysql-rc.yaml
kubectl create -f mysql-svc.yaml
image image

查看状态:

kubectl get pods
image

登陆到mysql中, 在node02节点登陆。IP为242

 kubectl get pod -o wide
image

输入docker ps 查看

 docker ps
image

进入容器

docker exec -it 485843113dbf /bin/bash
image

进入mysql

-h 为IP -u为用户名 -p为密码

mysql -h127.0.0.1 -uroot -pmysql
image

进行配置:

alter user 'root'@'%' identified with mysql_native_password by'root';

alter  user 'root'@'%' identified by 'mysql';

navicat进行连接测试:

image image image

OK!

上一篇下一篇

猜你喜欢

热点阅读