CentOS7搭建Kubernetes-dashboard管理服務



一、先決條件


  1、首先你必有現成的Kubernetes集羣,如果現在你一無所有,請參考:

  http://zlyang.blog.51cto.com/1196234/1951010

  2、建議採用etcd集羣,搭建過程請參考:

  http://zlyang.blog.51cto.com/1196234/1951164


二、部署Kubernetes-dashboard

  

  [所有機器:Master、Node1、Node2]

  1、安裝flannel(flannel爲管理Containers網絡)

  [root@k8s-master ~]# yum -y install epel-release flannel


  2、配置flanel


  [Master]

  [root@k8s-master ~]# vim /etc/sysconfig/flanneld

# Flanneld configuration options  


# etcd url location.  Point this to the server where etcd runs

FLANNEL_ETCD_ENDPOINTS="http://k8s-master:2379"


# etcd config key.  This is the configuration key that flannel queries

# For address range assignment

FLANNEL_ETCD_PREFIX="/atomic.io/network"


# Any additional options that you want to pass

#FLANNEL_OPTIONS=""


  [Node]

    [root@k8s-node1 ~]# vim /etc/sysconfig/flanneld

# Flanneld configuration options  


# etcd url location.  Point this to the server where etcd runs

FLANNEL_ETCD_ENDPOINTS="http://k8s-master:2379"


# etcd config key.  This is the configuration key that flannel queries

# For address range assignment

FLANNEL_ETCD_PREFIX="/atomic.io/network"


# Any additional options that you want to pass

#FLANNEL_OPTIONS=""


  3、添加Etcd網絡配置

  [Master]

  [root@k8s-master ~]# mkdir -p /atomic.io/network/

  [root@k8s-master ~]# chmod -R 777 /atomic.io

  [root@k8s-master ~]# etcdctl mk /atomic.io/network/config '{"Network":"10.254.0.0/16"}'

   ****** 注:此IP爲/etc/kubernetes/apiserver中{KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16" }填寫的地址


  4、啓動flannel服務

  [所有機器]

  [root@k8s-master ~]# systemctl start flanneld.service

  [root@k8s-master ~]# systemctl enable flanneld.service


  5、修改Kubernetes所有Node節點kubelet設置中添加dns信息,否則會報錯

  

  [Node1/Node2]

  [root@k8s-node1 ~]# vim /etc/kubernetes/kubelet

  ###

# kubernetes kubelet (minion) config


# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)

KUBELET_ADDRESS="--address=0.0.0.0"


# The port for the info server to serve on

KUBELET_PORT="--port=10250"


# You may leave this blank to use the actual hostname

KUBELET_HOSTNAME="--hostname-override=k8s-node1"


# location of the api-server

KUBELET_API_SERVER="--api-servers=http://k8s-master:8080"


# pod infrastructure container

KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"


# Add your own!

#KUBELET_ARGS=""

KUBELET_ARGS="--cluster-dns=223.5.5.5 --cluster-domain=k8s-master"


  6、重啓Node上的服務

  [Master]

for SERVICES in flanneld etcd kube-apiserver kube-controller-manager kube-scheduler; do     systemctl restart $SERVICES;     systemctl enable $SERVICES;     systemctl status $SERVICES ;   done


  [Node]

for SERVICES in flanneld kube-proxy kubelet docker; do     systemctl restart $SERVICES;     systemctl enable $SERVICES;     systemctl status $SERVICES ; done


  7、安裝dashboard

    

    [Node1/Node2]

    a、導入images

      ***由於牆的原因,需要先導入images,如果你可以***,忽略此步驟 

    下載地址:鏈接: http://pan.baidu.com/s/1kVuthYn 密碼: m2hv


    b、導入:

    [root@k8s-node1 ~]# docker load < kubernetes-dashboard.tar.gz


    c、查看

    [root@k8s-node1 ~]# docker images

REPOSITORY                                            TAG                 IMAGE ID            CREATED             SIZE

gcr.io/google_containers/kubernetes-dashboard-amd64   v1.6.2              bd4d50b8499e        8 days ago          139 MB


  8、創建dashboard容器

    [Master]

    a、下載kubernetes-dashboar.yaml文件

    [root@k8s-master ~]# git clone https://github.com/jdedu/kubernetes.git


    b、修改其中標紅項

    [root@k8s-master ~]# vim kubernetes/kubernetes-dashboard.yaml

    kind: Deployment

apiVersion: extensions/v1beta1

metadata:

  labels:

    app: kubernetes-dashboard

    version: v1.1.1

  name: kubernetes-dashboard

  namespace: kube-system

spec:

  replicas: 1

  selector:

    matchLabels:

      app: kubernetes-dashboard

  template:

    metadata:

      labels:

        app: kubernetes-dashboard

    spec:

      containers:

      - name: kubernetes-dashboard

        image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.6.2

        imagePullPolicy: Always

        ports:

        - containerPort: 9090

          protocol: TCP

        args:

        - --apiserver-host=http://192.168.80.130:8080

        livenessProbe:

          httpGet:

            path: /

            port: 9090

          initialDelaySeconds: 30

          timeoutSeconds: 30

---

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


  9、創建dashboard容器

  [Master]

  [root@k8s-master ~]# kubectl create -f kubernetes-dashboard.yaml

deployment "kubernetes-dashboard" created

service "kubernetes-dashboard" created

  

  10、查看狀態

  a、查看pods

  [root@k8s-master ~]# kubectl get pods --namespace=kube-system

NAME                                    READY     STATUS              RESTARTS   AGE

kubernetes-dashboard-1607234690-3bnk2   0/1       ContainerCreating   0          34s


  b、查看構建詳細信息

  [root@k8s-master ~]# kubectl describe pods kubernetes-dashboard-1607234690-3bnk2 --namespace=kube-system


Name:   kubernetes-dashboard-1607234690-3bnk2

Namespace:  kube-system

Node:   k8s-node2/192.168.80.132

Start Time: Thu, 03 Aug 2017 17:15:50 +0800

Labels:   app=kubernetes-dashboard

    pod-template-hash=1607234690

Status:   Pending

IP:   

Controllers:  ReplicaSet/kubernetes-dashboard-1607234690

Containers:

  kubernetes-dashboard:

    Container ID: 

    Image:    gcr.io/google_containers/kubernetes-dashboard-amd64:v1.6.2

    Image ID:   

    Port:   9090/TCP

    Args:

      --apiserver-host=http://192.168.80.130:8080

    State:      Waiting

      Reason:     ContainerCreating

    Ready:      False

    Restart Count:    0

    Liveness:     http-get http://:9090/ delay=30s timeout=30s period=10s #success=1 #failure=3

    Volume Mounts:    <none>

    Environment Variables:  <none>

Conditions:

  Type    Status

  Initialized   True 

  Ready   False 

  PodScheduled  True 

No volumes.

QoS Class:  BestEffort

Tolerations:  <none>

Events:

  FirstSeen LastSeen  Count From      SubObjectPath Type    Reason    Message

  --------- --------  ----- ----      ------------- --------  ------    -------

  2m    2m    1 {default-scheduler }      Normal    Scheduled Successfully assigned kubernetes-dashboard-1607234690-3bnk2 to k8s-node2

  

三、測試

  a、在測試機上添加host信息

  192.168.80.130  k8s-master


  b、使用瀏覽器輸入:http://k8s-master:8080/ui



四、錯誤

  

  [錯誤1]

  [root@k8s-master ~]# kubectl describe pods kubernetes-dashboard-1607234690-3bnk2 --namespace=kube-system


  1s    1s    1 {kubelet k8s-node2}           Warning   FailedSync  Error syncing pod, skipping: failed to "StartContainer" for "kubernetes-dashboard" with CrashLoopBackOff: "Back-off 10s restarting failed container=kubernetes-dashboard pod=kubernetes-dashboard-980055440-l9zl5_kube-system(870d02e1-7810-11e7-9517-000c296a54e8)"

  

  再次使用kubectl logs查看具體錯誤信息

  [root@k8s-master ~]# kubectl logs kubernetes-dashboard-1607234690-l6gfk --namespace=kube-system


No request provided. Skipping authorization header

Error while initializing connection to Kubernetes apiserver. This most likely means that the cluster is misconfigured (e.g., it has invalid apiserver certificates or service accounts configuration) or the --apiserver-host param points to a server that does not exist. Reason: Get http://k8s-master:8080/version: dial tcp: lookup k8s-master on 223.5.5.5:53: no such host

Refer to the troubleshooting guide for more information: https://github.com/kubernetes/dashboard/blob/master/docs/user-guide/troubleshooting.md


  [解決方案]

[root@k8s-master ~]# vim kubenetes-dashboard.yaml

- --apiserver改成ip,不要使用域名


  此過程中可能會遇到很多問題,如果需要幫助,請發郵件至:[email protected]


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章