1. 程式人生 > >kubernetes叢集部署DashBoard

kubernetes叢集部署DashBoard

搭建K8s DashBoard

叢集結構:

型別 主機名 ip
Master k8s_master 192.168.3.216
Node k8s_client1 192.168.3.217
Node k8s_client2 192.168.3.219

以下操作都在k8s_master上執行: 一、映象下載 [[email protected]_master ~]# docker pull docker.io/siriuszg/kubernetes-dashboard-amd64:v1.5.1 Trying to pull repository docker.io/siriuszg/kubernetes-dashboard-amd64 ...  sha256:d0aebe2567a6b11d090403746f63df9dccd32aec9192decfd3794b0cce528930: Pulling from docker.io/siriuszg/kubernetes-dashboard-amd64 9d25d3817204: Pull complete  Digest: sha256:d0aebe2567a6b11d090403746f63df9dccd32aec9192decfd3794b0cce528930 Status: Downloaded newer image for docker.io/siriuszg/kubernetes-dashboard-amd64:v1.5.1

[[email protected]_master ~]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure Using default tag: latest Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...  Pulling repository registry.access.redhat.com/rhel7/pod-infrastructure c99574180d51: Pull complete  1ada7c88ed3d: Pull complete  bcb4a96d0b39: Pull complete  Status: Downloaded newer image for registry.access.redhat.com/rhel7/pod-infrastructure:latest

二、配置kubernetes的dashboard 1、需要以下兩個kubernetes-dashboard和dashboard-service配置檔案。 kubernetes-dashboard.yaml  #需修改images和增加- --apiserver-host=http://192.168.3.216:8080

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  labels:
    app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: kubernetes-dashboard
  template:
    metadata:
      labels:
        app: kubernetes-dashboard
      # Comment the following annotation if Dashboard must not be deployed on master
      annotations:
        scheduler.alpha.kubernetes.io/tolerations: |
          [
            {
              "key": "dedicated",
              "operator": "Equal",
              "value": "master",
              "effect": "NoSchedule"
            }
          ]
    spec:
      containers:
      - name: kubernetes-dashboard
        image: docker.io/siriuszg/kubernetes-dashboard-amd64:v1.5.1
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9090
          protocol: TCP
        args:
          # Uncomment the following line to manually specify Kubernetes API server Host
          # If not specified, Dashboard will attempt to auto discover the API server and connect
          # to it. Uncomment only if the default does not work.
        - --apiserver-host=http://192.168.3.216:8080
        livenessProbe:
          httpGet:
            path: /
            port: 9090
          initialDelaySeconds: 30
          timeoutSeconds: 30

dashboard-service.yaml

#不需要做修改
kind: Service
apiVersion: v1
metadata:
  labels:
    app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 9090
  selector:
    app: kubernetes-dashboard

2、執行啟動,dashboard搭建完成。 [[email protected]_master ~]# kubectl create -f kubernetes-dashboard.yaml deployment "kubernetes-dashboard" created [[email protected]_master ~]# kubectl create -f dashboard-service.yaml  service "kubernetes-dashboard" created

3、驗證: 執行以下命令 [[email protected]_master ~]# kubectl get deployment --all-namespaces NAMESPACE NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE kube-system kubernetes-dashboard 1 1 1 1 1m [[email protected]_master ~]# kubectl get svc --all-namespaces NAMESPACE NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE default kubernetes 10.254.0.1 <none> 443/TCP 5d kube-system kubernetes-dashboard 10.254.141.158 <nodes> 80:31633/TCP 1m [[email protected]_master ~]# kubectl get pod -o wide --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE kube-system kubernetes-dashboard-1270457039-t1z15 1/1 Running 0 2m 10.8.43.2 192.168.3.219

5、刪除應用 [[email protected]_master ~]# kubectl delete deployment kubernetes-dashboard --namespace=kube-system deployment "kubernetes-dashboard" deleted [[email protected]_master ~]# kubectl delete svc kubernetes-dashboard --namespace=kube-system service "kubernetes-dashboard" deleted

報錯解決: 1、無法拉取映象registry.access.redhat.com/rhel7/pod-infrastructure:latest [[email protected]_master ~]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...  open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory 解決方法: [[email protected] ~]# yum install *rhsm* -y

2、瀏覽器開啟ui介面報錯

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "no endpoints available for service \"kubernetes-dashboard\"",
  "reason": "ServiceUnavailable",
  "code": 503
}

解決方法: KUBE_ADMISSION_CONTROL配置中預設需要認證,編輯配置檔案,在KUBE_ADMISSION_CONTROL中,去除SecurityContextDeny,ServiceAccount [[email protected]_master ~]# vim /etc/kubernetes/apiserver  KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota" 重啟服務,正常開啟