zoukankan      html  css  js  c++  java
  • kubernetes实战(二十八):Kubernetes一键式资源管理平台Ratel安装及使用

    1. Ratel是什么?

      

      Ratel是一个Kubernetes资源平台,基于管理Kubernetes的资源开发,可以管理Kubernetes的Deployment、DaemonSet、StatefulSet、Service、Ingress、Pods、Nodes、Role、ClusterRole、Rolebinding、ClusterRoleBinding、Secret、ConfigMap、PV、PVC等。主要用于以图形化的方式管理k8s的各类资源,提高维护k8s集群的效率及降低出错的概率。

    2. 安装Ratel

      请查看最新文档: https://github.com/dotbalo/ratel-doc

    2.1 配置文件解析

      Ratel默认是安装到需要管理的k8s集群中的任意一个集群(需要和其他集群能够通信)。所以需要现有一个集群,可以https://www.cnblogs.com/dukuan/p/12104600.html快速搭建一个高可用k8s 1.17.x集群。

     

      Ratel的配置文件采用yaml格式,参数如下:

     servers.yaml是ratel的配置文件, 格式如下:
            - serverName: 'test1'
              serverAddress: 'https://1.1.1.1:8443'
              #serverAdminUser: 'test1'
              #serverAdminPassword: 'test1#'
              serverAdminToken: 'null'
              serverDashboardUrl: "https://k8s.test1.com.cn"
              production: 'false'
              kubeConfigPath: "/mnt/test1.config"
            其中管理的方式有两种(Token暂不支持): 
                账号密码和kubeconfig形式, 只需配置一种即可, kubeconfig优先级高

      参数解析:

            serverName: 集群别名
            serverAddress: Kubernetes APIServer地址
            serverAdminUser: Kubernetes管理员账号(需要配置basic auth)
            serverAdminPassword: Kubernetes管理员密码
            serverAdminToken: Kubernetes管理员Token // 暂不支持
            serverDashboardUrl: Kubernetes官方dashboard地址
            kubeConfigPath: Kubernetes kube.config路径(绝对路径)
        kubeConfigPath 通过secret挂载到容器的/mnt目录或者其他目录

    2.2 创建Ratel Secret

      其中test1.config是集群test1的配置文件,test2.config是集群test2的配置文件,需要一一对应

    kubectl create secret generic ratel-config  --from-file=test1.config --from-file=test2.config --from-file=servers.yaml -n kube-system

    2.3 部署Ratel

      部署Ratel的Yaml文件如下:

            apiVersion: apps/v1
            kind: Deployment
            metadata:
              labels:
                app: ratel
              name: ratel
              namespace: kube-system
            spec:
              replicas: 1
              selector:
                matchLabels:
                  app: ratel
              strategy:
                rollingUpdate:
                  maxSurge: 1
                  maxUnavailable: 0
                type: RollingUpdate
              template:
                metadata:
                  creationTimestamp: null
                  labels:
                    app: ratel
                spec:
                  containers:
                    - command:
                        - sh
                        - -c
                        - ./ratel -c /mnt/servers.yaml
                      env:
                        - name: TZ
                          value: Asia/Shanghai
                        - name: LANG
                          value: C.UTF-8
                        - name: ProRunMode
                          value: prod
                        - name: ADMIN_USERNAME
                          value: admin
                        - name: ADMIN_PASSWORD
                          value: ratel_password
                      image: dotbalo/ratel:v0.1alpha
                      imagePullPolicy: Always
                      livenessProbe:
                        failureThreshold: 2
                        initialDelaySeconds: 10
                        periodSeconds: 60
                        successThreshold: 1
                        tcpSocket:
                          port: 8888
                        timeoutSeconds: 2
                      name: ratel
                      ports:
                        - containerPort: 8888
                          name: web
                          protocol: TCP
                      readinessProbe:
                        failureThreshold: 2
                        initialDelaySeconds: 10
                        periodSeconds: 60
                        successThreshold: 1
                        tcpSocket:
                          port: 8888
                        timeoutSeconds: 2
                      resources:
                        limits:
                          cpu: 1000m
                          memory: 520Mi
                        requests:
                          cpu: 100m
                          memory: 100Mi
                      volumeMounts:
                        - mountPath: /mnt
                          name: ratel-config
                  dnsPolicy: ClusterFirst
                  imagePullSecrets:
                    - name: myregistrykey
                  restartPolicy: Always
                  schedulerName: default-scheduler
                  securityContext: {}
                  terminationGracePeriodSeconds: 30
                  volumes:
                    - name: ratel-config
                      secret:
                        defaultMode: 420
                        secretName: ratel-config 

      创建Ratel的Service和Ingress的yaml文件如下:

    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app: ratel
      name: ratel
      namespace: kube-system
    spec:
      ports:
        - name: container-1-web-1
          port: 8888
          protocol: TCP
          targetPort: 8888
      selector:
        app: ratel
      type: ClusterIP
    ---
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: ratel
      namespace: kube-system
    spec:
      rules:
      - host: krm.test.com
        http:
          paths:
          - backend:
              serviceName: ratel
              servicePort: 8888
            path: /

      

      配置参数说明:

            ProRunMode: 区别在于dev模式打印的是debug日志, 其他模式是info级别的日志, 实际使用时应该配置为非dev
            ADMIN_USERNAME: ratel自己的管理员账号
            ADMIN_PASSWORD: ratel自己的管理员密码
            实际使用时账号密码应满足复杂性要求,因为ratel可以直接操作所配置的资源。
            其他无需配置, 端口配置暂不支持。

      部署完毕后可以通过krm.test.com进行访问(域名按需配置)

    2.4 访问Ratel

      

      登录后可以查看到集群列表

      点击Cluster Name可以查看到当前集群部分信息

      单击资源数量可以查看资源列表,比如Node

      或者Deployment

      

      更多详情查看:https://github.com/dotbalo/ratel-doc

    3. 使用Ratel创建Deployment

      点击Deployment --> 创建

    3.1 基本信息填写

      

       填写说明

      •   选择集群: 选择之前配置的集群, 按serverName区分,选择集群后,会自动弹出Namespace的选择框。
      •   Namespace: 当前Deployment需要创建在哪个Namespace,Namespace的选择框支持搜索功能。
      •   尽量部署至不同宿主机: 此选项相当于添加了一个Pod的Affinity的软策略,基于selector实现。
      •   部署至不同宿主机: 此选项相当于添加了一个Pod的Affinity的硬性策略策略,基于selector实现。
      •   更新策略: Deployment的更新策略,此处和DaemonSet和StatefulSet更新策略不一致。
      •   副本数: Pod的个数,可以使用鼠标滚轮或者直接键入的方式更改。
      •   私有仓库Secret: 用于私有仓库镜像下载的账号密码,需要提前创建,点击刷新会自动获取集群的docker registry类型的secret。

       可选参数配置

       填写说明

      •   Labels:Labels是Deployment的label标签,当属于Deployment名字时,会自动填写一个Labels和Selector,可以按需修改、添加和删除。
      •   Selectors: Selectors是Pod的Labels和Deployment的Selector,按需修改、添加和删除。
      •   HostAliases: HostAliases是hosts文件配置,按需修改、添加和删除。
      •   NodeSelector: 节点选择器,按需修改、添加和删除。
      •   内核配置: Pod中的内核配置。
      •   Taint: 容忍配置。

    3.2 Volume配置

      基本配置填写完成以后,点击Next(必须)进入到填写Volume的视图

       填写说明

        如上图所示,目前所支持的Volume配置有HostPath、Secret、ConfigMap、EmptyDir、PVC。
        上述的Secret、ConfigMap、PVC、StorageClass无需手动输入,单击刷新后即可自动自动获取到当前集群的相关信息。

      填写内容如下

    3.3 Container配置

      填写完Volume配置以后,点击Next填写Container配置

    3.3.1 Container 1配置

      

     

    3.3.2 Container 2配置

     

     

       填写说明

      •   Container配置目前几乎支持所有常见配置,Container的名称会在Deployment名称键入后自动填写一个默认的,可以按需修改。
      •   可以配置多个Container,按需添加、修改和删除。
      •   启动命令和启动参数按需修改,逗号分隔,如果启动命令或者启动参数含有逗号,需要以变量的方式传入,比如启动命令是--configEnv=test1,prd
      •   此时test1,prd需要配置成变量,之后通过--configEnv=$ConfigEnv注入。
      •   集群的CPU和内存资源按需配置,直接拖动即可。
      •   健康检查按需配置,目前支持httpGet、tcpSocket、exec方式。
      •   preStop和postStart按需配置。
      •   高权限运行是添加privilege=true参数至Container。
      •   容器端口按需配置和添加,目前支持三种协议配置。
      •   容器环境变量,支持三种方式的容器变量配置,按需添加、修改和删除。
        •     字符变量: key value变量,不能留空。
        •     EnvFrom: 从ConfigMap和Secret中获取变量配置。
        •     ValueFrom: 目前支持FieldRef、ConfigMapRef、SecretRef和ResourceFieldRef配置。
      •   文件挂载配置:
        •     文件挂载配置必须先添加Volume配置,否则无法创建文件挂载。
        •     Volume名称自动获取创建Volume。

    3.4 Init Container配置

      Init Container配置和Container大致相同

    3.5 Service配置

      创建Deployment、DaemonSet和StatefulSet的页面,嵌入了简单的Service和Ingress配置。
      如图所示,在配置完Container后,如果需要添加Service(默认不添加),在开启service配置后,会根据container的端口配置自动生成Service的配置,可以按需修改、添加和删除。此页面Service仅支持ClusterIP和NodePort两种类型。

    3.6 Ingress配置

      如图所示,在配置完Service后,如果需要添加Ingress(默认不添加),在开启Ingress后,会根据Service配置默认生成一个Ingress配置,可以按需修改、添加和删除。
      如需开启https,需要提前添加tls类型的域名证书,点击刷新后即可自动读取当前集群的当前Namespace的tls类型的证书列表,无tls类型的证书无法开启https。
      去除前缀的意思是: 访问www.test1.com/a/test.html 会自动变成www.test1.com/test.html。

    3.7 创建资源

      上述有不规范填写,比如名称不能包含大写的,Ratel会自动转换为小写。创建成功页面如下

      

    4. 创建资源查看

      相对于手动创建,不仅降低了出错概率,同时也无需掌握yaml文件的每个参数含义,大大提高了k8s集群的管理效率。

    4.1 查看创建的Deployment

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      annotations:
        deployment.kubernetes.io/revision: "1"
      creationTimestamp: "2019-11-18T10:19:57Z"
      generation: 1
      labels:
        app: nginx
      name: nginx
      namespace: default
      resourceVersion: "33645965"
      selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/nginx
      uid: f857546a-09ec-11ea-bf14-f80f41f365d0
    spec:
      progressDeadlineSeconds: 600
      replicas: 3
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: nginx
      strategy:
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 0
        type: RollingUpdate
      template:
        metadata:
          creationTimestamp: null
          labels:
            app: nginx
        spec:
          affinity:
            podAntiAffinity:
              preferredDuringSchedulingIgnoredDuringExecution:
              - podAffinityTerm:
                  labelSelector:
                    matchExpressions:
                    - key: app
                      operator: In
                      values:
                      - nginx
                  namespaces:
                  - default
                  topologyKey: kubernetes.io/hostname
                weight: 1
          containers:
          - args:
            - sleep 3600
            command:
            - sh
            - -c
            env:
            - name: TZ
              value: Asia/Shanghai
            - name: LANG
              value: C.UTF-8
            - name: testValueFrom
              valueFrom:
                resourceFieldRef:
                  containerName: nginx
                  divisor: "0"
                  resource: requests.memory
            envFrom:
            - secretRef:
                name: default-token-hgfm8
            image: nginx
            imagePullPolicy: IfNotPresent
            lifecycle: {}
            livenessProbe:
              exec:
                command:
                - echo 0
              failureThreshold: 2
              initialDelaySeconds: 30
              periodSeconds: 10
              successThreshold: 1
              timeoutSeconds: 2
            name: nginx
            ports:
            - containerPort: 8080
              name: web
              protocol: TCP
            readinessProbe:
              exec:
                command:
                - echo 0
              failureThreshold: 2
              initialDelaySeconds: 30
              periodSeconds: 10
              successThreshold: 1
              timeoutSeconds: 2
            resources:
              limits:
                cpu: 164m
                memory: 273Mi
              requests:
                cpu: 10m
                memory: 10Mi
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
            volumeMounts:
            - mountPath: /usr/share/zoneinfo/Asia/Shanghai
              name: tz-config
            - mountPath: /etc/localtime
              name: tz-config
            - mountPath: /etc/timezone
              name: timezone
            - mountPath: /mnt/testSecret
              name: testsecret
            - mountPath: /mnt/testConfigMap
              name: testconfigmap
            - mountPath: /mnt/testempty
              name: testemptydir
          - command:
            - sh
            - -c
            - sleep 3600
            env:
            - name: TZ
              value: Asia/Shanghai
            - name: LANG
              value: C.UTF-8
            - name: test
              value: a
            - name: testFieldRef
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            envFrom:
            - configMapRef:
                name: runner-xxx-gitlab-runner
            image: nginx
            imagePullPolicy: IfNotPresent
            lifecycle: {}
            name: nginx2
            resources:
              limits:
                cpu: 48m
                memory: 52Mi
              requests:
                cpu: 10m
                memory: 10Mi
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
            volumeMounts:
            - mountPath: /usr/share/zoneinfo/Asia/Shanghai
              name: tz-config
            - mountPath: /etc/localtime
              name: tz-config
            - mountPath: /etc/timezone
              name: timezone
            - mountPath: /mnt/testConfigMap
              name: testconfigmap
            - mountPath: /mnt/testPVC
              name: testpvc
          dnsPolicy: ClusterFirst
          imagePullSecrets:
          - name: myregistrykey
          initContainers:
          - command:
            - sh
            - -c
            - sleep3
            env:
            - name: TZ
              value: Asia/Shanghai
            - name: LANG
              value: C.UTF-8
            image: nginx
            imagePullPolicy: Always
            name: initcontainer
            resources:
              limits:
                cpu: 100m
                memory: 100Mi
              requests:
                cpu: 10m
                memory: 10Mi
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
            volumeMounts:
            - mountPath: /usr/share/zoneinfo/Asia/Shanghai
              name: tz-config
            - mountPath: /etc/localtime
              name: tz-config
            - mountPath: /etc/timezone
              name: timezone
          nodeSelector:
            env: test
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext:
            sysctls:
            - name: net.core.somaxconn
              value: "16384"
            - name: net.ipv4.tcp_max_syn_backlog
              value: "16384"
          terminationGracePeriodSeconds: 30
          tolerations:
          - effect: NoSchedule
            key: node-role.kubernetes.io/master
            operator: Exists
          volumes:
          - hostPath:
              path: /usr/share/zoneinfo/Asia/Shanghai
              type: ""
            name: tz-config
          - hostPath:
              path: /etc/timezone
              type: ""
            name: timezone
          - name: testsecret
            secret:
              defaultMode: 420
              secretName: default-token-hgfm8
          - configMap:
              defaultMode: 420
              name: runner-xxx-gitlab-runner
            name: testconfigmap
          - emptyDir: {}
            name: testemptydir
          - name: testpvc
            persistentVolumeClaim:
              claimName: gitrunner-workspace

    4.2 查看创建Service

    [root@k8s-master01 ~]# kubectl get svc nginx -oyaml
    apiVersion: v1
    kind: Service
    metadata:
      creationTimestamp: "2019-11-18T10:19:56Z"
      labels:
        app: nginx
      name: nginx
      namespace: default
      resourceVersion: "33645941"
      selfLink: /api/v1/namespaces/default/services/nginx
      uid: f833a327-09ec-11ea-bf14-f80f41f365d0
    spec:
      clusterIP: 50.104.173.155
      ports:
      - name: container-1-web-1
        port: 8080
        protocol: TCP
        targetPort: 8080
      selector:
        app: nginx
      sessionAffinity: None
      type: ClusterIP
    status:
      loadBalancer: {}

    4.3 Ingress配置

    [root@k8s-master01 ~]# kubectl get ingress nginx-strip-path -o yaml
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /$2
      creationTimestamp: "2019-11-18T10:25:39Z"
      generation: 1
      name: nginx-strip-path
      namespace: default
      resourceVersion: "33646594"
      selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/nginx-strip-path
      uid: c42679fe-09ed-11ea-bf14-f80f41f365d0
    spec:
      rules:
      - host: www.test.com
        http:
          paths:
          - backend:
              serviceName: nginx
              servicePort: 8080
            path: /test(/|$)(.*)
    status:
      loadBalancer: {}

      Ratel项目地址:https://github.com/dotbalo/ratel-doc

  • 相关阅读:
    - (id)initWithCoder:(NSCoder *)decoder 的参数的作用
    pch定义的宏,文件引用报错,use of undeclared identifier
    tableView代理方法的调用时间,(主要是heightForRowAtIndexPath和cellForRowAtIndexPath调用时间)
    Receiver 'NSManagedObjectContext' for class message is a forward declaration 错误的解决方案
    delegate、notification、KVO的使用场景总结
    UIGestureRecognizer手势和scrollview冲突的简单解决
    CGAffineTransform中setTransform的几种类型以及注意事项
    使用"vuedraggable"插件实现列表排序功能;
    aliplayer的使用
    自制时间轴组件封装
  • 原文地址:https://www.cnblogs.com/dukuan/p/11883541.html
Copyright © 2011-2022 走看看