美文网首页
通过helm3.0部署redis

通过helm3.0部署redis

作者: OPS_Joy | 来源:发表于2020-11-13 16:07 被阅读0次

    进入github下载相应版本
    https://github.com/helm/helm
    下载后解压直接使用,可放至/usr/bin目录下,增加执行权限

    [root@myapp ~]# helm version
    WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /root/.kube/config
    WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /root/.kube/config
    version.BuildInfo{Version:"v3.3.4", GitCommit:"a61ce5633af99708171414353ed49547cf05013d", GitTreeState:"clean", GoVersion:"go1.14.9"}
    

    helm常用操作
    查看chart仓库:helm repo list
    添加chart仓库:helm repo add bitnami https://charts.bitnami.com/bitnami
    在线查看服务:helm search repo bitnami/redis
    在线部署redis:helm install redis1 bitnami/redis
    查看已安装的服务:helm list
    从仓库拉服务到本地:helm pull repo bitnami/redis
    增加NFS存储类,以方便动态扩展PV
    1.rbac.yaml

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: nfs-client-provisioner
      namespace: default        #根据实际环境设定namespace,下面类同
    ---
    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: nfs-client-provisioner-runner
    rules:
      - 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
        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
      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
    subjects:
      - kind: ServiceAccount
        name: nfs-client-provisioner
        namespace: default
    roleRef:
      kind: Role
      name: leader-locking-nfs-client-provisioner
      apiGroup: rbac.authorization.k8s.io
    

    2.创建NFS资源的StorageClass,nfs-StorageClass.yaml

    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: managed-nfs-storage
    provisioner: qgg-nfs-storage #这里的名称要和provisioner配置文件中的环境变量PROVISIONER_NAME保持一致parameters:  archiveOnDelete: "false"
    

    3.创建NFS provisioner,nfs-provisioner.yaml

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nfs-client-provisioner
      labels:
        app: nfs-client-provisioner
      namespace: default  #与RBAC文件中的namespace保持一致
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: nfs-client-provisioner
      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: quay.io/external_storage/nfs-client-provisioner:latest
              volumeMounts:
                - name: nfs-client-root
                  mountPath: /persistentvolumes
              env:
                - name: PROVISIONER_NAME
                  value: qgg-nfs-storage  #provisioner名称,请确保该名称与 nfs-StorageClass.yaml文件中的provisioner名称保持一致
                - name: NFS_SERVER
                  value: 172.16.20.58   #NFS Server IP地址
                - name: NFS_PATH  
                  value: /data/volumes    #NFS挂载卷
          volumes:
            - name: nfs-client-root
              nfs:
                server: 172.16.20.58  #NFS Server IP地址
                path: /data/volumes     #NFS 挂载卷
    

    依次创建yaml
    kubectl create -f rbac.yaml
    kubectl create -f nfs-storage.yaml
    kubectl create -f nfs-provisioner.yaml
    查看存储类
    [root@harbor opt]# kubectl get sc
    NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
    managed-nfs-storage qgg-nfs-storage Delete Immediate false 145m
    修改拉下来的redis中的values.yaml,如下部分:指定存储类,关闭主从模式

    ##
        storageClass: "managed-nfs-storage"
        accessModes:
        - ReadWriteOnce
        size: 8Gi
    ## Cluster settings
    cluster:
      enabled: false
      slaveCount: 2
    

    部署redis

    [root@harbor opt]#  helm install -name redis-1 -n default -f values.yaml stable/redis
    ** Please be patient while the chart is being deployed **
    Redis can be accessed via port 6379 on the following DNS name from within your cluster:
    redis-1-master.default.svc.cluster.local
    To get your password run:
        export REDIS_PASSWORD=$(kubectl get secret --namespace default redis-1 -o jsonpath="{.data.redis-password}" | base64 --decode)
    To connect to your Redis server:
    1. Run a Redis pod that you can use as a client:
       kubectl run --namespace default redis-1-client --rm --tty -i --restart='Never' \
        --env REDIS_PASSWORD=$REDIS_PASSWORD \
       --image docker.io/bitnami/redis:5.0.7-debian-10-r32 -- bash
    2. Connect using the Redis CLI:
       redis-cli -h redis-1-master -a $REDIS_PASSWORD
    To connect to your database from outside the cluster execute the following commands:
        kubectl port-forward --namespace default svc/redis-1-master 6379:6379 &
        redis-cli -h 127.0.0.1 -p 6379 -a $REDIS_PASSWORD
    

    查看部署

    [root@harbor opt]# kubectl get pods
    NAME                                      READY   STATUS    RESTARTS   AGE
    nfs-client-provisioner-556f974d45-j5lqp   2/2     Running   1          46m
    redis-1-client                            2/2     Running   0          31m
    redis-1-master-0                          2/2     Running   0          35m
    

    进入客户端测试

    I have no name!@redis-1-client:/$ redis-cli -h redis-1-master -a $REDIS_PASSWORD
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    redis-1-master:6379> set joyname chen
    OK
    redis-1-master:6379> get joyname
    "chen"
    redis-1-master:6379> quit
    

    相关文章

      网友评论

          本文标题:通过helm3.0部署redis

          本文链接:https://www.haomeiwen.com/subject/phivbktx.html