枫之叶 世界是平衡的,每个人都是通过自己的努力,去决定自己生活的样子。

Kubernetes学习环境快速搭建:kubernetes-vagrant-centos-cluster

K

背景

尝试Kubernetes学习环境快速搭建。

安装

基本安装&调试

Kubernetes v1.18.0

# 常用
vagrant halt
vagrant up
# login to node1
vagrant ssh node1
# run the prosivision scripts
/vagrant/hack/k8s-init.sh
exit
# login to node2
vagrant ssh node2
# run the prosivision scripts
/vagrant/hack/k8s-init.sh
exit
# login to node3
vagrant ssh node3
# run the prosivision scripts
/vagrant/hack/k8s-init.sh
sudo -i
cd /vagrant/hack
./deploy-base-services.sh
exit

配置~/.kube/config

$ cd /Users/zengjianfeng/Documents/projects_data/kubernetes-vagrant-centos-cluster


# 安装后执行一次即可,也有可能会和本地冲突,因此使用本地kubernetes时可能还要改回来,待测试
$ cp ~/.kube/config ~/.kube/config.bak
$ cp conf/admin.kubeconfig ~/.kube/config

查看token:本地访问1(需要配置~/.kube/config)

$ cd /Users/zengjianfeng/Documents/projects_data/kubernetes-vagrant-centos-cluster

$ hack/get-dashboard-token.sh
Login to kubernetes dashboard at https://172.17.8.101:8443 with the following token
eyJhbGciOiJSUzI1NiIsImtpZCI6IkRmN01LR1k5dzV6eDhFbVZUczg1aVQzVHdQRUs3ZTBva2YxVWlBcTYyM3MifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi10b2tlbi1ncWZqZiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJhZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImNkYTAzODUwLTJjZjktNDgwMC1hYmVhLTNhYWYyMzY1MDgyNiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTphZG1pbiJ9.DC18VEfSDDbdnGSiiNq0DiRP3OJLTfl0c9qc9BNf-_8OHExHjjbdaaPsfx6GfJdjWB-enk0Tukw7A-NyiVnxEecFjGTmty7bjrwdSttQM-qkUW68tG85ig2jQYKWiNGCdChMinl1RbH8lt0ErfJoYzcDume8MOOGqOdrz5Cs1E7PWgGfEB8HX_z5S12QwCLS_Cxj9tNukpbwVDEV-9rgwBb7gR1rk9U_1MzYQXc-zGTSvXJhOaY_hvDxuwEYB8Raqrz6zAuQaf-8rJMQ_XQvi0qmQTOeVBSiYVbatYdLnGrDK3_vXIAPPXokUdzibjLixTgu3oPAEB_na5kQy9Lstw

查看token:本地访问2(需要配置~/.kube/config)

$ kubectl -n kube-system describe secret `kubectl -n kube-system get secret|grep admin-token|cut -d " " -f1`|grep "token:"|tr -s " "|cut -d " " -f2

查看token:token的值也可以在vagrant up的日志的最后看到

node3出错:

node3: configure node3
    node3: Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /usr/lib/systemd/system/kubelet.service.
    node3: Created symlink from /etc/systemd/system/multi-user.target.wants/kube-proxy.service to /usr/lib/systemd/system/kube-proxy.service.
    node3: deploy coredns
    node3: error: unable to recognize "STDIN": no matches for kind "Deployment" in version "extensions/v1beta1"
    node3: /home/vagrant
    node3: deploy kubernetes dashboard
    node3: error: unable to recognize "/vagrant/addon/dashboard/kubernetes-dashboard.yaml": no matches for kind "Deployment" in version "apps/v1beta2"
    node3: create admin role token
    node3: clusterrolebinding.rbac.authorization.k8s.io/admin created
    node3: serviceaccount/admin created
    node3: the admin role token is:
    node3: eyJhbGciOiJSUzI1NiIsImtpZCI6IkRmN01LR1k5dzV6eDhFbVZUczg1aVQzVHdQRUs3ZTBva2YxVWlBcTYyM3MifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi10b2tlbi1oOG5keiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJhZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImQ4YjBhOWQ4LWFlODItNDFjYy1iNDZmLTEwMTkzN2FhMWM3ZCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTphZG1pbiJ9.uvdKV_fxRDlKiE9aQx_DK7yPI6OS3P9YbsBmngb-H1QzNlI_ep1SqZujHI_SzaAnu4BUVE2KASvZzHfuwpZubCAUnT0rbU_PvxcWIQkxuavCLo3MXVk2XzW_9LC-DUvupeNazletplh7SlRvgkuVaYYrsJiEEvN9ocJV6o623nUqM1SmK_6Us5SjP1q6S5gm8YPEyDFeFLYKGlRcNF-rhgpWITOoasGy6RtrDx9urqxlLkp1A7qafW9HYCScepdvJoB1fZaEfp5XjblOWaTklenYnOc7pfSceFVCvCbuZhSzBezN3m_mzsibBk52QtTg1Lfdurwb7dRs9xAyYw2kyA
    node3: login to dashboard with the above token
    node3: Error from server (NotFound): services "kubernetes-dashboard" not found
    node3: https://172.17.8.101:
    node3: install traefik ingress controller
    node3: error: unable to recognize "/vagrant/addon/traefik-ingress/traefik.yaml": no matches for kind "DaemonSet" in version "extensions/v1beta1"
    node3: Configure Kubectl to autocomplete

解决错误1:修改/vagrant/addon/dashboard/kubernetes-dashboard.yaml

node3: deploy coredns
    node3: error: unable to recognize "STDIN": no matches for kind "Deployment" in version "extensions/v1beta1"
    node3: /home/vagrant
    node3: deploy kubernetes dashboard
    node3: error: unable to recognize "/vagrant/addon/dashboard/kubernetes-dashboard.yaml": no matches for kind "Deployment" in version "apps/v1beta2"

解决错误2:修改/vagrant/addon/traefik-ingress/traefik.yaml

node3: login to dashboard with the above token
    node3: Error from server (NotFound): services "kubernetes-dashboard" not found
    node3: https://172.17.8.101:
    node3: install traefik ingress controller
    node3: error: unable to recognize "/vagrant/addon/traefik-ingress/traefik.yaml": no matches for kind "DaemonSet" in version "extensions/v1beta1"

还是出错

# kubectl apply -f /vagrant/addon/traefik-ingress/traefik.yaml
error: unable to recognize "/vagrant/addon/traefik-ingress/traefik.yaml": no matches for kind "DaemonSet" in version "extensions/v1"

查看

kubectl apply -f https://k8s.io/examples/controllers/daemonset.yaml

参考:https://kubernetes.io/zh/docs/concepts/workloads/controllers/daemonset/

本地访问面板:
访问:https://172.17.8.101:8443
输入token后登录显示错误:

尝试重启后,此错误还是出现!
重启过程

vagrant halt
vagrant up
# login to node1
vagrant ssh node1
# run the prosivision scripts
/vagrant/hack/k8s-init.sh
exit
# login to node2
vagrant ssh node2
# run the prosivision scripts
/vagrant/hack/k8s-init.sh
exit
# login to node3
vagrant ssh node3
# run the prosivision scripts
/vagrant/hack/k8s-init.sh
sudo -i
cd /vagrant/hack
./deploy-base-services.sh
exit

node3可能会报错:

# ./deploy-base-services.sh
deploy coredns
error: unable to recognize "STDIN": no matches for kind "Deployment" in version "extensions/v1beta1"
deploy kubernetes dashboard
secret/kubernetes-dashboard-certs created
serviceaccount/kubernetes-dashboard created
role.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-minimal created
deployment.apps/kubernetes-dashboard created
service/kubernetes-dashboard created
create admin role token
clusterrolebinding.rbac.authorization.k8s.io/admin created
serviceaccount/admin created
the admin role token is:
eyJhbGciOiJSUzI1NiIsImtpZCI6IkRmN01LR1k5dzV6eDhFbVZUczg1aVQzVHdQRUs3ZTBva2YxVWlBcTYyM3MifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi10b2tlbi1ncWZqZiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJhZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImNkYTAzODUwLTJjZjktNDgwMC1hYmVhLTNhYWYyMzY1MDgyNiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTphZG1pbiJ9.DC18VEfSDDbdnGSiiNq0DiRP3OJLTfl0c9qc9BNf-_8OHExHjjbdaaPsfx6GfJdjWB-enk0Tukw7A-NyiVnxEecFjGTmty7bjrwdSttQM-qkUW68tG85ig2jQYKWiNGCdChMinl1RbH8lt0ErfJoYzcDume8MOOGqOdrz5Cs1E7PWgGfEB8HX_z5S12QwCLS_Cxj9tNukpbwVDEV-9rgwBb7gR1rk9U_1MzYQXc-zGTSvXJhOaY_hvDxuwEYB8Raqrz6zAuQaf-8rJMQ_XQvi0qmQTOeVBSiYVbatYdLnGrDK3_vXIAPPXokUdzibjLixTgu3oPAEB_na5kQy9Lstw
login to dashboard with the above token
https://172.17.8.101:8443
install traefik ingress controller
error: unable to recognize "addon/traefik-ingress/traefik.yaml": no matches for kind "DaemonSet" in version "extensions/v1"

解决:

# kubectl apply -f https://k8s.io/examples/controllers/daemonset.yaml
daemonset.apps/fluentd-elasticsearch created

访问控制面板需要新产生的token!

组件安装

Heapster监控

# 本地执行即可
$ kubectl apply -f addon/heapster/
service/monitoring-grafana created
serviceaccount/heapster created
clusterrolebinding.rbac.authorization.k8s.io/heapster created
configmap/heapster-config created
configmap/eventer-config created
service/heapster created
service/monitoring-influxdb created
unable to recognize "addon/heapster/heapster-controller.yaml": no matches for kind "Deployment" in version "extensions/v1beta1"
unable to recognize "addon/heapster/influxdb-grafana-controller.yaml": no matches for kind "Deployment" in version "extensions/v1beta1"

解决

$ kubectl delete -f addon/heapster/

尝试使用上面安装出错的解决方案

# kubectl apply -f https://k8s.io/examples/controllers/daemonset.yaml

应该是可以的,这里显示安装过了,之后用下面修改文件的方式安装的

修改两个文件Deployment相关内容:
* addon/heapster/influxdb-grafana-controller.yaml
* addon/heapster/heapster-controller.yaml

kind: Deployment
#apiVersion: extensions/v1beta1
apiVersion: apps/v1

再次执行,解决

访问Grafana出问题,暂时没有解决;
另,虚拟机方式太耗资源,可能要放弃了;

参考

(完)

About the author

Add Comment

作者: admin
枫之叶 世界是平衡的,每个人都是通过自己的努力,去决定自己生活的样子。

碎言碎语

有点小懒,不定期更新

分类目录

标签