目录
一、Metrics部署
在新版的Kubernetes中系统资源的采集均使用Metrics-Server,可以通过Metrics采集节点和Pod的内存、磁盘、CPU和网络的使用率
[root@node1 ~]# wget https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml
##修改配置
vim /root/Metrics-Server/components.yaml
创建pod:
[root@node1 Metrics-Server]# kubectl apply -f /root/Metrics-Server
components.yaml
验证:
二、Dashboard部署
Dashboard用于展示集群中的各类资源,同时也可以通过Dashboard实时查看Pod的日志以及在容器中执行的命令等
[root@node1]# mkdir Dashboard
[root@node1 Dashboard]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.6.0/aio/deploy/recommended.yaml
##修改配置文件
##官方提供的资源清单里面的secret证书在有些浏览器中无法访问,所以需要注释掉,然后后期自己添加
#因为自动生成的证书很多浏览器无法使用,所以我们自己创建,注释掉kubernetes-dashboard-certs对象声明
[root@node1 Dashboard]# vim recommended.yaml //注释掉yaml里下方内容
#apiVersion: v1
#kind: Secret
#metadata:
# labels:
# k8s-app: kubernetes-dashboard
# name: kubernetes-dashboard-certs
# namespace: kubernetes-dashboard
#type: Opaque
##创建pod
[root@node1 Dashboard]#kubectl apply -f recommended.yaml --validate=false //加--validate=false忽略报错
##由于缺镜像所有手动下载对应镜像
[root@node1 Dashboard]# docker pull kubernetesui/dashboard:v2.6.0
[root@node1 Dashboard]# docker pull kubernetesui/metrics-scraper:v1.0.8
##因为该pod使用的namespace是kubernetes-dashboard,所有查看kubernetes-dashboard
[root@node1 Dashboard]# kubectl get pods -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-d86bd9646-tgcnr 1/1 Running 0 6m20s
kubernetes-dashboard-6d96d6f767-slfsg 1/1 Running 0 6m20s
验证:
##修改配置使随意访问一台机器都可以访问到dashboard
[root@node1 ~]# kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
修改前:58 type: ClusterIP
修改后:58 type: NodePort
##查看网络
[root@node1 ~]# kubectl get svc -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dashboard-metrics-scraper ClusterIP 10.105.127.123 <none> 8000/TCP 60m
kubernetes-dashboard NodePort 10.111.50.172 <none> 443:32532/TCP 65m
##创建超级管理员用户,tokenkey:
[root@node1 ~]# vim /root/Dashboard/admin.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: admin-user
annotations:
rbac.authorrization.kubernetes.io/autoipdate: "true"
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kube-system
查看admin的token:
token: eyJhbGciOiJSUzI1NiIsImtpZCI6Ik5OZktyQTZ3M3dzX3FWdTl1T0w1VmNMaWVQT19Kb2ZsVklhYXFlY2ZBUEUifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLTI4d3pjIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI4Y2IwMTU4Ny00MzBjLTRjZjItOGY2MS1lYWE5MjYzYTA0OGIiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.NN_wXb5SPV6ntesmInBoKCfY4dz72Tc_eIqEwOUXEdmhZJWwvP_xI2Q7iGoc6R45yLZXXSEmhywRBoSAipIcS0WJCYN3Cxvynxl5FjH9lLtsR0IGnIIvGob8gutgW6lBJ0XtezDxra0oRN6S_GZAr66yDW9rttUqsmhU6Hy4DGQ2OFue-qZTubM9Y_LciWlT2rcAj1CVfMvPxLhDtlrTIJgLOqeoYW1RkrGB2J9f_N56JOPz3WpwSrteKLz14ZybJr5UdwAgRiJ76FHkeCPCOzRa1-s82RpI1BOaRUAgjN9ZtZS-zgGxoAWAKqy4_pBQ_fyY6OD37OQkOR622ZotVg
登录DashBoard:
三、Kuboard安装
[root@node1 ~]# mkdir kuboard
[root@node1 kuboard]# wget https://kuboard.cn/install-script/kuboard-beta.yaml
安装:
查看Token:
echo $(kubectl -n kube-system get secret $(kubectl -n kube-system get secret | grep kuboard-user | awk '{print $1}') -o go-template='{{.data.token}}' | base64 -d)
四、集群验证
编写nginx.yaml
[root@node1 ~]# vim busybox.yaml
apiVersion: v1
kind: Pod
metadata:
name: busybox
namespace: default
spec:
containers:
- name: busybox
image: busybox:1.28
command:
- sleep
- "3600"
imagePullPolicy: IfNotPresent
restartPolicy: Always
##导入yaml文件
[root@node1 ~]# kubectl apply -f busybox.yaml
验证:
1、pod必须能解析service
2、pod必须能解析跨namespace的services
3、每个节点都必须能访问k8s的svc 443端口以及kube-dns的services 53端口
[root@node1 ~]# yum -y install telnet //所有节点都安装
4、Pod与pod之间能通
a) 同namespace之间能通信
b)跨namespace能通信
c)跨机器能通信
本文含有隐藏内容,请 开通VIP 后查看