kubernetes-dashboard2.0和metrics-server安装k8s(二)——Devops(四)
目录1 安装kubernetes-dashboard1.1 下载配置文件1.2 创建证书1.3 安装 kubernetes-dashboard1.4 创建管理员权限1.5 查看并复制用户Token1.6 查看日志2 安装metrics-server2.1 Node节点下载镜像2.2 下载配置文件1 安装kubernetes-dashboard1.1 下载配置文件https://github.com
·
目录
1 安装kubernetes-dashboard
1.1 下载配置文件
https://github.com/kubernetes/dashboard/blob/master/aio/deploy/recommended.yaml
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
spec:
type: NodePort
ports:
- port: 443
targetPort: 8443
nodePort: 30001
selector:
k8s-app: kubernetes-dashboard
---
#因为自动生成的证书很多浏览器无法使用,所以我们自己创建,注释掉kubernetes-dashboard-certs对象声明
#apiVersion: v1
#kind: Secret
#metadata:
# labels:
# k8s-app: kubernetes-dashboard
# name: kubernetes-dashboard-certs
# namespace: kubernetes-dashboard
#type: Opaque
---
1.2 创建证书
#创建命名空间
kubectl create namespace kubernetes-dashboard
# 创建key文件
openssl genrsa -out dashboard.key 2048
#证书请求
openssl req -days 36000 -new -out dashboard.csr -key dashboard.key -subj '/CN=dashboard-cert'
#自签证书
openssl x509 -req -in dashboard.csr -signkey dashboard.key -out dashboard.crt
#创建kubernetes-dashboard-certs对象
kubectl create secret generic kubernetes-dashboard-certs --from-file=dashboard.key --from-file=dashboard.crt -n kubernetes-dashboard
部分命令
# 删除POD
kubectl delete pod PODNAME --force --grace-period=0
# 删除NAMESPACE
kubectl delete namespace NAMESPACENAME --force --grace-period=0
# 删除default namespace下的pod名为pod-to-be-deleted-0
ETCDCTL_API=3 etcdctl del /registry/pods/default/pod-to-be-deleted-0
# 删除需要删除的NAMESPACE
etcdctl del /registry/namespaces/NAMESPACENAME
#强制删除pod
kubectl delete pod [pod name] --force --grace-period=0 -n [namespace]
# <secret file>这里常用的就是property文件,内容是key=value
kubectl create secret generic <secret name> --from-env-file=<secret file> -n <namespace>
# 删除secret
kubectl delete secret <secret name> -n <namespace>
# 查看有哪些secret:
kubectl get secrets -n <namespace>
# 查看secret详细信息
kubectl describe secrets <secret name> -n <namespace>
1.3 安装 kubernetes-dashboard
kubectl create -f recommended.yaml
kubectl delete -f recommended.yaml #清理
#检查结果
kubectl get pods,svc -n kube-system
kubectl get pods -A -o wide
kubectl get service -n kubernetes-dashboard -o wide
1.4 创建管理员权限
dashboard-admin.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: kubernetes-dashboard
name: dashboard-admin
namespace: kubernetes-dashboard
---
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
[root@k8s-master ~]# kubectl create -f dashboard-admin.yaml
1.5 查看并复制用户Token
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep dashboard-admin | awk '{print $1}')
Data
====
token: eyJhbGciOiJSUzI1NiIsImtpZCI6InFqUXlIeVE0b1Z0X1AwaGxHb2xibU5NUDhseDNlcWFXQkhURmZJRzJwMDAifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkZWZhdWx0LXRva2VuLWo3cGZ6Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImRlZmF1bHQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJjN2IzMzZjZS1kNTVhLTQ3NzAtYTRiMC00OWQ0NGE2ZWM5ODgiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6ZGVmYXVsdCJ9.r73ShiOAYEzrmUgXz6SqDHcnqhEjueYqxjJYQJyIQOavxLoVDQD7UaNhf4ZBJcnVJdGB2DFAT2hJHKzx6JrcMkhkoIrqeQXqWP6XynehkIGQqgH37J5xs04s-ShMkni-sRHdN5XMA4vU_WzRVDp5sMIIZvKhE1mMtu_WiVsO_bV0YCZ4lUm6kLpJtRApXpRNJHtqlBQq2BAYTmSVJQwi0Ptfub-kFQ9d_4qR7CJRoGctFLQu0DJZq87Knim5XFIdG7OcuY30872W9TsQC4RrULOfKAnaVPONskM1kxPxO90XXdTjfoGQJLEOksavdFSF2wEgJ-IZg_xLSfiQNvqfNw
ca.crt: 1025 bytes
namespace: 20 bytes
1.6 查看日志
kubectl logs kubernetes-dashboard-56484d4c5-sk9fd --namespace=kubernetes-dashboard
2 安装metrics-server
2.1 Node节点下载镜像
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
2.2 下载配置文件
https://github.com/kubernetes-sigs/metrics-server/releases
mkdir metrics-server-0.3.6
复制metrics-server-0.3.6/deploy/1.8+路径下的yaml文件
修改metrics-server-deployment.yaml
spec:
hostNetwork: true #新增
serviceAccountName: metrics-server
volumes:
# mount in tmp so we can safely use from-scratch images and/or read-only containers
- name: tmp-dir
emptyDir: {}
containers:
- name: metrics-server
image: k8s.gcr.io/metrics-server-amd64:v0.3.6
imagePullPolicy: IfNotPresent
command:
- /metrics-server #新增
- --kubelet-insecure-tls #新增
- --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP #新增
volumeMounts:
- name: tmp-dir
mountPath: /tmp
kubectl create -f metrics-server/
kubectl get pods -A -o wide
kubectl top nodes
kubectl top pods --all-namespace
如果出现: error: metrics not available yet 问题,说明服务还未完成启动
参考资料: https://www.cnblogs.com/shunzi115/p/12438702.html
更多推荐
已为社区贡献1条内容
所有评论(0)