您的位置:

Kuboard安装指南

一、Kuboard部署

Kuboard是一个基于Kubernetes的Web控制台,可以帮助用户直观地管理和监控Kubernetes集群。在开始安装Kuboard之前,需要先部署一个Kubernetes集群。以下示例是在GKE上进行部署。


gcloud container clusters create kuboard \
  --zone asia-east1-b \
  --machine-type n1-standard-2 \
  --num-nodes 3 \
  --enable-autoscaling --min-nodes 1 --max-nodes 10

接下来,在Kubernetes集群中创建一个Kuboard命名空间,并使用kubectl命令安装以下资源:


kubectl create ns kuboard
kubectl apply -f https://raw.githubusercontent.com/kuboard/kuboard-press/master/crd/kuboard_v2alpha1_dashboard_crd.yaml
kubectl apply -f https://raw.githubusercontent.com/kuboard/kuboard-press/master/crd/kuboard_v2alpha1_notice_crd.yaml
kubectl apply -f https://raw.githubusercontent.com/kuboard/kuboard-press/master/crd/kuboard_v2alpha1_terminal_crd.yaml
kubectl apply -f https://raw.githubusercontent.com/kuboard/kuboard-press/master/crd/kuboard_v2alpha1_screenshot_crd.yaml
kubectl apply -f https://raw.githubusercontent.com/kuboard/kuboard-press/master/crd/kuboard_v2alpha1_telemetry_crd.yaml
kubectl apply -f https://raw.githubusercontent.com/kuboard/kuboard-press/master/crd/kuboard_v2alpha1_settings_crd.yaml
kubectl -n kuboard apply -f https://kuboard.cn/install/v2alpha1/kuboard.yaml

二、Kuboard安装在哪里

Kuboard的安装位置取决于部署Kubernetes集群的位置。在本示例中,Kuboard被部署在谷歌云计划(GKE)的Asia East地区。然而,Kuboard也可以部署在其他云环境中,例如AWS、Azure和阿里云等。

三、Kuboard安装Nginx

Kuboard需要一个反向代理服务器来进行路由转发和流量负载均衡。在这里我们选用Nginx进行演示:


apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      name: nginx-ingress-controller
  template:
    metadata:
      labels:
        name: nginx-ingress-controller
    spec:
      containers:
        - name: nginx-ingress-controller
          image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.19.0
          args:
            - /nginx-ingress-controller
            - --configmap=$(POD_NAMESPACE)/nginx-configuration
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
            - name: http
              containerPort: 80
            - name: https
              containerPort: 443
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-ingress-lb
  namespace: kube-system
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
spec:
  type: LoadBalancer
  selector:
    name: nginx-ingress-controller
  ports:
    - name: http
      port: 80
      targetPort: 80
      protocol: TCP
    - name: https
      port: 443
      targetPort: 443
      protocol: TCP

四、Kuboard安装Traefik

除了Nginx之外,Kuboard也可以使用Traefik进行反向代理和负载均衡。以下是一个实现Traefik的Kubernetes资源描述:


apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name:traefik-ingress-controller
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      name: traefik-ingress-controller
  template:
    metadata:
      labels:
        name: traefik-ingress-controller
    spec:
      containers:
      - image: traefik:v2.0
        name: traefik-ingress-lb
        ports:
        - containerPort: 80
          name: http
        - containerPort: 443
          name: https
        args:
        - --api=true
        - --api.insecure=true
---
apiVersion: v1
kind: Service
metadata:
  name: traefik-ingress-lb
  namespace: kube-system
spec:
  selector:
    name: traefik-ingress-controller
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: 80
  - name: https
    port: 443
    protocol: TCP
    targetPort: 443

五、Kuboard安装ELK

Kuboard可以与ELK(Elasticsearch、Logstash和Kibana)一起使用,以便更好地理解和监控集群中的日志。

以下是一个基于Helm的ELK安装的示例:


helm repo add elastic https://helm.elastic.co
helm install elasticsearch elastic/elasticsearch \
  --version=7.5.1 \
  --namespace=kuboard \
  --set nodeGroup.affinitySlotsNumber=2 \
  --set replicas=2 \
  --set esJavaOpts="-Xms512m -Xmx1000m" \
  --set antiAffinityTopologyKey="failure-domain.beta.kubernetes.io/zone"
helm install kibana elastic/kibana \
  --version=7.5.1 \
  --namespace=kuboard
helm install logstash elastic/logstash \
  --version=7.5.1 \
  --namespace=kuboard

六、Kuboard安装套件Loki

Loki是一个开源日志集合器和查询系统,与Kubernetes兼容。

以下是一个实现Loki的Kubernetes YAML部署文件:


apiVersion: v1
kind: ServiceAccount
metadata:
  namespace: kuboard
  name: loki
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  namespace: kuboard
  name: loki-role
rules:
  - apiGroups: [""]
    resources:
    - "pods"
    - "namespaces"
    - "nodes"
    - "clusters"
    - "secrets"
    verbs:
    - get
    - watch
    - list
  - nonResourceURLs: ["/metrics"]
    verbs: ["get"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  namespace: kuboard
  name: loki-role-binding
subjects:
  - kind: ServiceAccount
    name: loki
    namespace: kuboard
roleRef:
  kind: ClusterRole
  name: loki-role
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: kuboard
  name: loki-config
data:
  loki-config.yaml: |-
    auth_enabled: false
    server:
      http_listen_port: 3100
      grpc_listen_port: 9095
    schema_config:
      configs:
        - from: "2020-04-29"
          store: loki
          object_store: ""
          schema: v11
          index:
            prefix: "loki_index"
            period: 24h
    storage_config:
      loki:
        tenant_id: "default"
        server:
          grpc_client_config:
            plaintext: true
          http_listen_port: 10800
        chunk_size_limit: 1048576
        table_manager:
          retention_deletes_enabled: true
          retention_period: 24h # how long to keep the indices around in object storage
          retention_delete_delay: 1m45s # how long to wait between enqueuing an index for deletion and actually deleteting it
    ingester:
      lifecycler:
        address: 127.0.0.1
        ring:
          kvstore:
            store: inmemory
          replica_count: 1
    compactor:
      working_directory: /tmp/loki/compactor
      shared_store: gcs
      shared_store_gcs_bucket: loki-for-dev
      retention_enabled: true
      retention_period: 72h
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: kuboard
  name: loki
spec:
  replicas: 1
  selector:
    matchLabels:
      app: loki
  template:
    metadata:
      labels:
        app: loki
    spec:
      serviceAccountName: loki
      containers:
        - name: loki
          image: grafana/loki:0.4.0
          args:
            - -config.file=/etc/loki-config/loki-config.yaml
            - -target=all
          ports:
            - containerPort: 3100
              name: http
            - containerPort: 9095
              name: grpc
          volumeMounts:
            - name: config
              mountPath: /etc/loki-config
      volumes:
        - name: config
          configMap:
            name: loki-config

七、Kuboard Spray

Spray是Kuboard的另一个开源扩展,它使用Twitter Spray框架构建了一个Scala编写的Web服务。

以下示例演示了如何将Spray部署到Kuboard上:


apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: spray
  name: spray
  namespace: kuboard
spec:
  replicas: 1
  selector:
    matchLabels:
      app: spray
  template:
    metadata:
      labels:
        app: spray
    spec:
      containers:
        - image: puckel/docker-airflow:1.10.2
          imagePullPolicy: Always
          name: airflow
          env:
            - name: AIRFLOW__CORE__LOAD_EXAMPLES
              value: "no"
          ports:
            - containerPort: 8080
          volumeMounts:
            - name: dags
              mountPath: /usr/local/airflow/dags
      restartPolicy: Always
      volumes:
        - name: dags
          configMap:
            name: dag-config
            items:
                - key: sample.py
                  path: dag.py
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: spray
  name: spray
  namespace: kuboard
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 8080
  selector:
    app: spray

八、Kuboard和KubeSphere

Kuboard和KubeSphere都是适合于Kubernetes的可视化管理平台。如果你已经在使用KubeSphere,你可以将Kuboard安装在KubeSphere中,以扩展KubeSphere的功能。

以下是将Kuboard与KubeSphere集成的示例:


apiVersion: helm.kubesphere.io/v1alpha1
kind: HelmChart
metadata:
  name: kuboard
  namespace: kubesphere-system
spec:
  releaseName: kuboard
  chartName: kuboard
  chartRepository: "https://kuboard.github.io/kuboard/"
  softwareName: kuboard
  version: 0.9
  values:
    persistence:
      enabled: true
      storageClass: "standard"
      size: "10Gi"
    ingress:
      enabled: true
      annotations:
        kubernetes.io/ingress.class: "nginx"
        nginx.ingress.kubernetes.io/rewrite-target: "/"
      path: "/"
      hosts:
        - host: "kuboard.example.com"
          paths:
            - "/*"