1. 程式人生 > >CentOS7搭建Kubernetes dashboard

CentOS7搭建Kubernetes dashboard

CentOS7 搭建 Kubernetes

CentOS7搭建Kubernetes dashboard
一 環境聲明
Centos7三臺,master節點一臺,node節點兩臺
Dashboard需要一個鏡像,需要執行命令下載:
docker pull mritd/kubernetes-dashboard-amd64:v1.5.1
ps:還有很多其他的鏡像也能搭建dashboard,不過這個版本是漢化版

註意:兩個node節點都需要下載此鏡像,master節點不用,因為dashboard的pod會被master調度到兩臺node之一去創建,不會在master本地創建。

二.具體操作
以下操作全部在master節點執行:
1.編輯dashboard-controller.yaml,創建dashboard的pod

註意修改紅色字體的部分!
vim dashboard-controller.yaml,內容如下:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: kubernetes-dashboard
namespace: kube-system
labels:
k8s-app: kubernetes-dashboard
kubernetes.io/cluster-service: "true"
spec:
selector:
matchLabels:
k8s-app: kubernetes-dashboard
template:
metadata:

labels:
k8s-app: kubernetes-dashboard
annotations:
scheduler.alpha.kubernetes.io/critical-pod: ‘‘
scheduler.alpha.kubernetes.io/tolerations: ‘[{"key":"CriticalAddonsOnly", "operator":"Exists"}]‘
spec:
containers:

  • name: kubernetes-dashboard
    image: mritd/kubernetes-dashboard-amd64:v1.5.1
    imagePullPolicy: IfNotPresent
    resources:
    limits:
    cpu: 100m
    memory: 50Mi
    requests:
    cpu: 100m
    memory: 50Mi
    ports:
    • containerPort: 9090
      args:
      • --apiserver-host=http://10.0.2.90:8080
        livenessProbe:
        httpGet:
        path: /
        port: 9090
        initialDelaySeconds: 30
        timeoutSeconds: 30

紅色字體解釋:

  1. mritd/kubernetes-dashboard-amd64:v1.5.1:dashboard的鏡像,如果你的不是此鏡像,請註意修改
  2. --apiserver-host=http://10.0.2.90:8080,填寫你master的apiserver地址,默認端口一般都是8080

===========================================================

OK,現在開始編輯dashboard-service.yaml,將dashboard的訪問端口映射到兩臺node宿主機的端口,以便外部訪問。
vim dashboard-service.yaml,內容如下:
apiVersion: v1
kind: Service
metadata:
name: kubernetes-dashboard
namespace: kube-system
labels:
k8s-app: kubernetes-dashboard
kubernetes.io/cluster-service: "true"
spec:
type: NodePort
selector:
k8s-app: kubernetes-dashboard
ports:

  • port: 80
    targetPort: 9090
    nodePort: 30003

紅色字體解釋:
port是指service的端口
targetport是指pod的端口
nodePort是指宿主機即node的端口,k8s外部就通過這個端口訪問dashboard

創建dashboard
kubectl create -f dashboard-controller.yaml
結果顯示:deployment "kubernetes-dashboard" created

kubectl create -f dashboard-service.yaml
結果顯示:service "kubernetes-dashboard" created

查看創建結果:
[root@k8s-master yaml]# kubectl get pods --namespace=kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE
kubernetes-dashboard-56bc76b6bb-b6kfx 1/1 Running 0 32s 172.18.0.194 node1

[root@k8s-master yaml]# kubectl get svc --namespace=kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes-dashboard NodePort 172.18.0.196 <none> 80:30003/TCP 13s

OK,創建成功,接下來就可以通過瀏覽器訪問node節點(兩個node任選一個都可以)的30003端口體驗kubernetes-dashboard:

CentOS7搭建Kubernetes dashboard