828华为云征文 | 使用Flexus云服务器X实例部署Kubernetes图形化管理平台
1. 基础部署环境说明
Kubernetes作为当今最流行的容器编排平台,随着云计算、微服务架构和DevOps文化的普及,Kubernetes在自动化部署、扩展和管理容器化应用程序方面扮演着越来越重要的角色。未来Kubernetes将继续优化其稳定性、安全性和易用性,以满足企业级应用的需求。同时随着边缘计算、AI和大数据等技术的融合,Kubernetes有望成为支撑下一代分布式应用的基础设施,推动整个IT行业的创新与发展。
本次选择使用华为Flexus云服务器X实例部署Kubernetes图形化管理平台,因为最近华为云828 B2B企业节正在举办,选择Flexus X云主机实例,享受定制化性能优化、99.99%的高可用性保障,以及全面的技术支持,让您的业务飞速发展,云端无忧!
2. 部署Kubernetes环境
因为本次主要是在Flexus云服务器X实例中部署Kubernetes图形化管理平台,所以Kubernetes环境的部署不是本篇的重点内容,但是Kubernetes图形化管理平台又依赖Kubernetes环境,所以本次使用kk
工具进行Kubernetes环境的部署。当然如果自己有Kubernetes环境,也可以跳过本章节,直接进行下面的部署过程。
[root@flexusx-3e9a ~]# export KKZONE=cn
[root@flexusx-3e9a ~]# curl -sfL https://get-kk.kubesphere.io | VERSION=v2.3.0 sh -
[root@flexusx-3e9a ~]# tar xvf kubekey-v2.3.0-linux-amd64.tar.gz
[root@flexusx-3e9a ~]# ./kk version --show-supported-k8s
v1.19.0
v1.19.8
v1.19.9
v1.20.4
v1.20.6
v1.20.10
v1.21.0
v1.21.1
……
[root@flexusx-3e9a ~]# ./kk create cluster --with-kubernetes v1.22.12
3. 部署Kubernetes Dashboard
[root@flexusx-3e9a ~]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
[root@flexusx-3e9a ~]# grep image recommended.yaml
image: registry.cn-hangzhou.aliyuncs.com/cloud_wzy/dashboard:v2.7.0
imagePullPolicy: IfNotPresent
image: registry.cn-hangzhou.aliyuncs.com/cloud_wzy/metrics-scraper:v1.0.8
[root@flexusx-3e9a ~]# kubectl apply -f recommended.yaml
[root@flexusx-3e9a ~]# kubectl get ns
NAME STATUS AGE
kubernetes-dashboard Active 21s
[root@flexusx-3e9a ~]# kubectl get pods -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-66fbb549b-g9n2j 1/1 Running 0 47s
kubernetes-dashboard-67c5c7dc6b-fqpnv 1/1 Running 0 47s
[root@flexusx-3e9a ~]# kubectl get svc -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dashboard-metrics-scraper ClusterIP 10.102.209.140 <none> 8000/TCP 2m12s
kubernetes-dashboard ClusterIP 10.101.169.76 <none> 443/TCP 2m12s
[root@flexusx-3e9a ~]# kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
......
selector:
k8s-app: kubernetes-dashboard
sessionAffinity: None
type: NodePort
[root@flexusx-3e9a ~]# kubectl get svc -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dashboard-metrics-scraper ClusterIP 10.102.209.140 <none> 8000/TCP 8m49s
kubernetes-dashboard NodePort 10.101.169.76 <none> 443:30156/TCP 8m49s
4. 创建登录账号token
创建SA(此SA账号用于和集群内的程序交互使用,可以参考我的其他博客了解SA账号作用):
[root@flexusx-3e9a ~]# kubectl create sa dashboardsa -n kube-system
[root@flexusx-3e9a ~]# kubectl get sa -n kube-system | grep dashboardsa
dashboardsa 0 57s
[root@flexusx-3e9a ~]# kubectl create clusterrolebinding rolebind-dashboard --clusterrole admin --serviceaccount kube-system:dashboardsa -n kube-system
因为从kubernetes 1.24版本开始,创建SA不再自动生成secrets,所以接下来需要手动创建一个secrets
手动创建secrets:官方参考手册
[root@flexusx-3e9a ~]# vim dashboardsa-secret.yaml
[root@flexusx-3e9a ~]# cat dashboardsa-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: secret-sa-sample
annotations:
kubernetes.io/service-account.name: "dashboardsa"
type: kubernetes.io/service-account-token
[root@flexusx-3e9a ~]# kubectl apply -f dashboardsa-secret.yaml -n kube-system
[root@flexusx-3e9a ~]# kubectl get secrets -n kube-system
NAME TYPE DATA AGE
secret-sa-sample kubernetes.io/service-account-token 3 12s
[root@flexusx-3e9a ~]# kubens kube-system
[root@flexusx-3e9a ~]# kubectl describe secrets secret-sa-sample
Name: secret-sa-sample
Namespace: kube-system
Labels: <none>
Annotations: kubernetes.io/service-account.name: dashboardsa
kubernetes.io/service-account.uid: 90bc6cea-5b6e-4a14-b271-3e3f26cb87a4
Type: kubernetes.io/service-account-token
Data
====
ca.crt: 1099 bytes
namespace: 11 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6IlJ5WnAtellKaHF2VWxpc0FvRTNoc2JTRkZFQ2VnY09SX1FlNjRDTTZjSmMifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJzZWNyZXQtc2Etc2FtcGxlIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImRhc2hib2FyZHNhIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiOTBiYzZjZWEtNWI2ZS00YTE0LWIyNzEtM2UzZjI2Y2I4N2E0Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZHNhIn0.rbqlQuYMx6YqAo0GOhMKbNkTRjGUkWOOfyndaQCqHzZckpxFUK5YRvvN88k5-DFA0L0nHBWx1LBijINgEKig9wsaB1VOU5tAsoDRdR5PSTeGrp6H5urVXVHQ5tTwug8G2P8BgDzu0eYGvihpEh27Ovt4H-CNmvfgvTIvlJ3rIopsierDhhtC2L0HyLtZK0b2__o4cbErcFGCmca6TVLMbOH__jCDtO4v80dKXN0VKevozc_l1aQ0KD-UGehpsE7nch2fx1IALyNLXbIlgUflTzXOvFyiNysiSXlzBQUITGLW37Htfqw9k2MaSfPTnHA1yn-ly4jKjWx5L0dQ1_UZdQ
5. 访问Kubernetes Dashboard
也可以选择使用Kubeconfig
方式登录,将kubernetes集群中/etc/kubernetes/admin.conf
文件下载到本地,然后再上传到此处即可。
[root@flexusx-3e9a ~]# kubectl get deployment -n demo
NAME READY UP-TO-DATE AVAILABLE AGE
wzy-demo2024 5/5 5 5 62m
[root@flexusx-3e9a ~]# kubectl get pod -n demo
NAME READY STATUS RESTARTS AGE
wzy-demo2024-5c757c7bc4-6655c 1/1 Running 0 62m
wzy-demo2024-5c757c7bc4-j8ngd 1/1 Running 0 62m
wzy-demo2024-5c757c7bc4-pp68q 1/1 Running 0 62m
wzy-demo2024-5c757c7bc4-rcqmt 1/1 Running 0 62m
wzy-demo2024-5c757c7bc4-tw598 1/1 Running 0 62m
[root@flexusx-3e9a ~]# kubectl get svc -n demo
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wzy-demo2024 LoadBalancer 10.98.123.58 192.168.24.237 80:31810/TCP 62m