编程知识 cdmana.com

k8s部署mariadb

1、构建mariadb的dockerfile

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

2、docker build打包并上传到harbor仓库

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

3、编写yaml文件

[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:这里面使用ceph-rbd作为默认starageclass,如何配置storageclass请查看前面的文章
4、使用kubectl apply部署到K8s
kubectl apply -f mariadb.yaml

版权声明
本文为[osc_xqyge9to]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4344760/blog/4840195

Scroll to Top