编程知识 cdmana.com

K8s deployment of MariaDB

1、 structure mariadb Of dockerfile

FROM mariadb:latest
ENV MYSQL_ROOT_PASSWORD 123456
ENV LANG zh_CN.UTF-8

2、docker build Pack and upload to harbor Warehouse

docker build -t xxx.xxx.com:10443/library/mariadb:latest .
docker push xxx.xxx.com:10443/library/mariadb:latest

3、 To write yaml file

[root@master mysql]# cat mariadb.yaml 
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mariadb-pvc
  namespace: wehgc-alpha
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
---
apiVersion: v1
kind: Service
metadata:
  name: mariadb
  namespace: wehgc-alpha
spec:
  ports:
  - nodePort: 33306
    port: 3306
    protocol: TCP
    targetPort: 3306
  selector:
    app: mariadb
  type: NodePort
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mariadb
  namespace: wehgc-alpha
spec:
  serviceName: mariadb
  replicas: 1
  selector:
    matchLabels:
      app: mariadb
  template:
    metadata:
      labels:
        app: mariadb
    spec:
      containers:
      - name: mariadb
        image: xxx.xxx.com:10443/library/mariadb:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 3306
          protocol: TCP
        volumeMounts:
        - mountPath: /var/lib/mysql
          name: data

      imagePullSecrets:
      - name: registry-pull-secret
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: mariadb-pvc

PS: It uses ceph-rbd As default starageclass, How to configure storageclass Please check the previous article
4、 Use kubectl apply Deploy to K8s
kubectl apply -f mariadb.yaml

版权声明
本文为[osc_ xqyge9to]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225121204133b.html

Scroll to Top