CentOS7搭建Kubernetes-dashboard管理服務

來源:互聯網
上載者:User

標籤:kubernetes   etcd   k8s   docker   flanal   openvswitch   



一、先決條件


  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網路)

  [[email protected] ~]# yum -y install epel-release flannel


  2、配置flanel


  [Master]

  [[email protected] ~]# 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]

    [[email protected] ~]# 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]

  [[email protected] ~]# mkdir -p /atomic.io/network/

  [[email protected] ~]# chmod -R 777 /atomic.io

  [[email protected] ~]# 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服務

  [所有機器]

  [[email protected] ~]# systemctl start flanneld.service

  [[email protected] ~]# systemctl enable flanneld.service


  5、修改Kubernetes所有Node節點kubelet設定中添加dns資訊,否則會報錯

  

  [Node1/Node2]

  [[email protected] ~]# 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,如果你可以翻牆,忽略此步驟

    :


    b、匯入:

    [[email protected] ~]# docker load < kubernetes-dashboard.tar.gz


    c、查看

    [[email protected] ~]# 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檔案

    [[email protected] ~]# git clone https://github.com/jdedu/kubernetes.git


    b、修改其中標紅項

    [[email protected] ~]# 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]

  [[email protected] ~]# kubectl create -f kubernetes-dashboard.yaml

deployment "kubernetes-dashboard" created

service "kubernetes-dashboard" created

  

  10、查看狀態

  a、查看pods

  [[email protected] ~]# kubectl get pods --namespace=kube-system

NAME                                    READY     STATUS              RESTARTS   AGE

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


  b、查看構建詳細資料

  [[email protected] ~]# 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]

  [[email protected] ~]# 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查看具體錯誤資訊

  [[email protected] ~]# 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


  [解決方案]

[[email protected] ~]# vim kubenetes-dashboard.yaml

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


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


本文出自 “Elephant” 部落格,請務必保留此出處http://zlyang.blog.51cto.com/1196234/1953399

CentOS7搭建Kubernetes-dashboard管理服務

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.