安装Dashboard
首先先下载官方的yaml文件
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta5/aio/deploy/recommended.yaml
访问方式
1、直接https
修改访问方式,这个地方可以随机分配也可以直接指定,在这里我指定了端口
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
type: NodePort
ports:
- port: 443
targetPort: 8443
nodePort: 30018 #指定端口为30018,不写则为随机分配
selector:
k8s-app: kubernetes-dashboard
2、kubectl proxy 方式访问
开启kubectl proxy
kubectl proxy --address='0.0.0.0' --accept-hosts='^*$'
访问地址
http://192.168.136.134:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login
这里的地址是master节点的地址
开始安装
kubectl create -f ~/recommended.yaml
检查pad是否启动
kubectl get pods -A -o wide
kubectl get service -n kubernetes-dashboard -o wide
创建账号
创建admin账号
cat <dashboard-admin.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: kubernetes-dashboard
name: dashboard-admin
namespace: kubernetes-dashboard
EOF
kubectl create -f dashboard-admin.yaml
为用户分配权限
cat <dashboard-admin-bind-cluster.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: dashboard-admin-bind-cluster-role
labels:
k8s-app: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: dashboard-admin
namespace: kubernetes-dashboard
EOF
kubectl create -f dashboard-admin-bind-cluster.yaml
查看token
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep dashboard-admin | awk '{print $1}')
选择第二个输入图中的token
因为我们没有安装metrics-server所以Pods的CPU、内存情况是看不到的,下面我们安装一下。
安装metrics-server
下载镜像包
docker pull bluersw/metrics-server-amd64:v0.3.6
docker tag bluersw/metrics-server-amd64:v0.3.6 k8s.gcr.io/metrics-server-amd64:v0.3.6
执行下面的命令
mkdir metrics-server
cd metrics-server
wget https://raw.githubusercontent.com/kubernetes-incubator/metrics-server/master/deploy/1.8%2B/aggregated-metrics-reader.yaml
wget https://raw.githubusercontent.com/kubernetes-incubator/metrics-server/master/deploy/1.8%2B/auth-delegator.yaml
wget https://raw.githubusercontent.com/kubernetes-incubator/metrics-server/master/deploy/1.8%2B/auth-reader.yaml
wget https://raw.githubusercontent.com/kubernetes-incubator/metrics-server/master/deploy/1.8%2B/metrics-apiservice.yaml
wget https://raw.githubusercontent.com/kubernetes-incubator/metrics-server/master/deploy/1.8%2B/metrics-server-deployment.yaml
wget https://raw.githubusercontent.com/kubernetes-incubator/metrics-server/master/deploy/1.8%2B/metrics-server-service.yaml
wget https://raw.githubusercontent.com/kubernetes-incubator/metrics-server/master/deploy/1.8%2B/resource-reader.yaml
修改配置文件
安装metrics-server
kubectl apply -f ./
访问一下就可以看到资源了
閱讀更多 SimOps 的文章