k8s部署mysql

k8s上:运行mysql镜像+配置文件-Java文档类资源-CSDN下载k8s上:运行mysql镜像+配置文件更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/cyw8998/86818799一.k8s主从环境搭建(参见我的其他文章)

二.书写mysql-service.yaml 并执行

apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 43306
  selector:
    app: mysql
  clusterIP: None

执行命令 kubectl apply -f mysql-service.yaml

三.书写mysql-deployment.yaml 并执行

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.7
        name: mysql
        env:
          # Use secret in real usage
        - name: MYSQL_ROOT_PASSWORD
          value: password
        ports:
        - containerPort: 43306
          name: mysql
        #volumeMounts:
        #- name: mysql-persistent-storage
          #mountPath: /var/lib/mysql
      #volumes:
      #- name: mysql-persistent-storage
       # persistentVolumeClaim:
        #  claimName: mysql-pv-claim

下载地址:k8s上:运行mysql镜像+配置文件-Java文档类资源-CSDN下载

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