Kubernetes部署系列:MySql单机版

第一步:创建pv

kind: PersistentVolume
apiVersion: v1
metadata:
  name: mysql-pv
  namespace: kube-public
spec:
  accessModes:
    - ReadWriteOnce      
  capacity:
    storage: 1Gi
  persistentVolumeReclaimPolicy: Retain
  storageClassName: nfs
  nfs:
    path: /storage/nfsdata/mysql    # nfs创建的目录 
    server: 192.168.194.104   # nfs的地址

第二步:创建pvc

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mysql-pvc
  namespace: kube-public
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: nfs

第三步:创建pod (安装nfs的机器,防火墙记得关闭)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  namespace: kube-public
spec:
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - name: mysql
        image: 192.168.194.104:8080/library/mysql:5.7.32  # 私有镜像仓库
        env:                        
        - name: MYSQL_ROOT_PASSWORD
          value: "123456" # 数据库root的密码
        ports:
        - containerPort: 3306
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql         
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pvc

 第四步:创建service

apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: kube-public
spec:
  type: NodePort
  ports:
  - port: 3306
    targetPort: 3306
    nodePort: 30011 # 对外暴露的接口
  selector:
    app: mysql

第五步:验证

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值