k8s安装mysql(简易版)

k8s安装mysql

//mysql-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: mysql-rc
  namespace: liyuan
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: mysql-pod
    spec:
      containers:
      - name: mysql-container
        image: mysql
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3306
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: Liyuan201227
        resources:
          limits:
            cpu: "0.1"
            memory: "300Mi"
          requests:
            cpu: "0.1"
            memory: "300Mi"

//mysql-svc.yaml
apiVersion: v1
kind: Service
metadata:
    name: mysql-svc
    namespace: liyuan
    labels:
        name: mysql-svc
spec:
    type: NodePort
    ports:
    - port: 3306
      protocol: TCP
      targetPort: 3306
      name: http
      nodePort: 30306
    selector:
      name: mysql-pod

进入mysql被调度的节点;
//centos7中防火墙关闭和端口无关
systemctl start firewall-cmd
firewall-cmd --zone=public --add-port=30306/tcp --permanent
firewall-cmd --reload

//mysql无法远程连接
进入mysql对应的容器
mysql --help |grep my.cnf
在这里插入图片描述
kubectl create -f mysql-rc.yaml
kubectl create -f mysql-svc.yaml

docker ps|grep mysql
docker exec -it b85b3f1facc1 bash

alter user ‘root’@’%’ identified with mysql_native_password by’root’;
alter user ‘root’@’%’ identified by ‘mysql’;

本地连接远程mysql
在这里插入图片描述
kubectl describe node liyuan-node2

//docker运行mysql检查image是否正常
//docker run -itd --name mysql-test -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql

你可能感兴趣的:(mysql,docker,数据库,k8s)