nfs,statefulset部署mysql

参见 https://blog.csdn.net/qq_33448670/article/details/79972401

https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner

---

apiVersion: storage.k8s.io/v1

kind: StorageClass

metadata:

  name: auto-nfs-storage

  annotations:

    storageclass.kubernetes.io/is-default-class: "true"

provisioner: k8s-sigs.io/nfs-subdir-external-provisioner

parameters:

  archiveOnDelete: "true"  ## 删除pv的时候,pv的内容是否要备份

reclaimPolicy: Delete

volumeBindingMode: WaitForFirstConsumer

---

apiVersion: apps/v1

kind: Deployment

metadata:

  name: nfs-client-provisioner

  labels:

    app: nfs-client-provisioner

  # replace with namespace where provisioner is deployed

  namespace: default

spec:

  replicas: 1

  strategy:

    type: Recreate

  selector:

    matchLabels:

      app: nfs-client-provisioner

  template:

    metadata:

      labels:

        app: nfs-client-provisioner

    spec:

      serviceAccountName: nfs-client-provisioner

      containers:

        - name: nfs-client-provisioner

          #image: k8s.gcr.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2

          image: registry.cn-hangzhou.aliyuncs.com/image-storage/nfs-subdir-external-provisioner:v4.0.2

          # resources:

          #    limits:

          #      cpu: 10m

          #    requests:

          #      cpu: 10m

          volumeMounts:

            - name: nfs-client-root

              mountPath: /data/nfs/auto

          env:

            - name: PROVISIONER_NAME

              value: k8s-sigs.io/nfs-subdir-external-provisioner

            - name: NFS_SERVER

              value: 192.168.155.130 ## 指定自己nfs服务器地址

            - name: NFS_PATH

              value: /data/nfs/auto  ## nfs服务器共享的目录

      volumes:

        - name: nfs-client-root

          nfs:

            server: 192.168.155.130 #注意这里的地址

            path: /data/nfs/auto

---

apiVersion: v1

kind: ServiceAccount

metadata:

  name: nfs-client-provisioner

  # replace with namespace where provisioner is deployed

  namespace: default

---

kind: ClusterRole

apiVersion: rbac.authorization.k8s.io/v1

metadata:

  name: nfs-client-provisioner-runner

rules:

  - apiGroups: [""]

    resources: ["nodes"]

    verbs: ["get", "list", "watch"]

  - apiGroups: [""]

    resources: ["persistentvolumes"]

    verbs: ["get", "list", "watch", "create", "delete"]

  - apiGroups: [""]

    resources: ["persistentvolumeclaims"]

    verbs: ["get", "list", "watch", "update"]

  - apiGroups: ["storage.k8s.io"]

    resources: ["storageclasses"]

    verbs: ["get", "list", "watch"]

  - apiGroups: [""]

    resources: ["events"]

    verbs: ["create", "update", "patch"]

---

kind: ClusterRoleBinding

apiVersion: rbac.authorization.k8s.io/v1

metadata:

  name: run-nfs-client-provisioner

subjects:

  - kind: ServiceAccount

    name: nfs-client-provisioner

    # replace with namespace where provisioner is deployed

    namespace: default

roleRef:

  kind: ClusterRole

  name: nfs-client-provisioner-runner

  apiGroup: rbac.authorization.k8s.io

---

kind: Role

apiVersion: rbac.authorization.k8s.io/v1

metadata:

  name: leader-locking-nfs-client-provisioner

  # replace with namespace where provisioner is deployed

  namespace: default

rules:

  - apiGroups: [""]

    resources: ["endpoints"]

    verbs: ["get", "list", "watch", "create", "update", "patch"]

---

kind: RoleBinding

apiVersion: rbac.authorization.k8s.io/v1

metadata:

  name: leader-locking-nfs-client-provisioner

  # replace with namespace where provisioner is deployed

  namespace: default

subjects:

  - kind: ServiceAccount

    name: nfs-client-provisioner

    # replace with namespace where provisioner is deployed

    namespace: default

roleRef:

  kind: Role

  name: leader-locking-nfs-client-provisioner

  apiGroup: rbac.authorization.k8s.io

---

---

# https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/

apiVersion: apps/v1

kind: StatefulSet

metadata:

  name: mysql003

  namespace: default

  labels:

    app: mysql003

spec:

  selector:

    matchLabels:

      app: mysql003 # has to match .spec.template.metadata.labels

  serviceName: "mysql003"

  replicas: 1 # by default is 1

  template:

    metadata:

      labels:

        app: mysql003 # has to match .spec.selector.matchLabels

    spec:

      terminationGracePeriodSeconds: 10

      containers:

      - name: mysql003

        image: mysql/mysql-server:8.0

        resources:

            requests:

              cpu: 500m

              memory: 1024Mi

            limits:

              cpu: 10000m

              memory: 1024Mi

        env:

        - name: ACCEPT_EULA

          value: "Y"

        - name: MYSQL_ROOT_PASSWORD

          value: mysql678123

        - name: MYSQL_ROOT_USER

          value: root

        - name: MYSQL_SQL_MODE

          value: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

        - name: MYSQL_DATABASE

          value: db001

        - name: MYSQL_AUTHENTICATION_PLUGIN

          value: mysql_native_password

        - name: MYSQL_DATABASE

          value: db001

        - name: DATADIR

          value: /var/lib/mysql/data

        - name: MYSQL_ROOT_HOST

          value: '%'

        ports:

        - containerPort: 3306

          name: mysql003

        volumeMounts:

        - name: mysql-data

          mountPath: /var/lib/mysql

  volumeClaimTemplates:

  - metadata:

      name: mysql-data

    spec:

      storageClassName: auto-nfs-storage

      accessModes:

      - ReadWriteOnce

      resources:

        requests:

          storage: 100Mi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值