kubernetes v1.20项目之二进制安装部署Dashboard和CoreDNS(亲测)
kubernetes v1.20项目之二进制安装部署Dashboard和CoreDNS需要kubernetes-dashboard.yaml这个yaml,大家可以在我的资源里面下载,一起加油哈部署Dashboard[root@k8s-master01 k8s]# kubectl apply -f kubernetes-dashboard.yamlnamespace/kubernetes-dashb
·
kubernetes v1.20项目之二进制安装部署Dashboard和CoreDNS
需要kubernetes-dashboard.yaml这个yaml,大家可以在我的资源里面下载,一起加油哈
相关所需资源下载
链接:https://pan.baidu.com/s/1emtDOy7bzxlR_hUw6vY2GQ
提取码:a7j4
--来自百度网盘超级会员V2的分享
**部分文件需要更改ip地址或其他的配置,请改成自己的使用**
部署Dashboard
[root@k8s-master01 k8s]# kubectl apply -f kubernetes-dashboard.yaml
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created
[root@k8s-master01 k8s]# kubectl get pods,svc -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
pod/dashboard-metrics-scraper-7b59f7d4df-ggb65 0/1 ContainerCreating 0 19s
pod/kubernetes-dashboard-74d688b6bc-7nqpk 0/1 ContainerCreating 0 19s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/dashboard-metrics-scraper ClusterIP 10.0.0.126 <none> 8000/TCP 19s
service/kubernetes-dashboard NodePort 10.0.0.185 <none> 443:30001/TCP 21s
访问尝试一下
访问地址:https://NodeIP:30001
创建service account并绑定默认cluster-admin管理员集群角色
[root@k8s-master01 k8s]# kubectl create serviceaccount dashboard-admin -n kube-system
serviceaccount/dashboard-admin created
[root@k8s-master01 k8s]# kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
clusterrolebinding.rbac.authorization.k8s.io/dashboard-admin created
[root@k8s-master01 k8s]# kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
Name: dashboard-admin-token-tg4g7
Namespace: kube-system
Labels: <none>
Annotations: kubernetes.io/service-account.name: dashboard-admin
kubernetes.io/service-account.uid: 9b90f82c-f6ec-44a2-8355-2e72939b6318
Type: kubernetes.io/service-account-token
Data
====
ca.crt: 1359 bytes
namespace: 11 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6Iko4U2FOeE9nbGhNU3NZajdqS1NTeUJYQVQxWXNqTlVmYVpTREhoelJZcVUifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tdGc0ZzciLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiOWI5MGY4MmMtZjZlYy00NGEyLTgzNTUtMmU3MjkzOWI2MzE4Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.BQeNlsEnhCM1QVVY-Q6RyHCbDg22dyKKYQc2zZGAL_Wa3caDNX4YYYpYzTSN1UYYOaqlMzVrxkkkSvz2r6o2A3VrYOvHlQQ3gWIS_OD4-qbGoz1cNjwst1rMmVq-BFefcQvcqiP5JRGSwybAvsMGmgZ3KadHiggB3jws3ui0oqbEE-j3H0JkSMqsyKCPm3JDiBW8tQpVKcrljBMVgsiUlB5fF-MsfqLRDx8h45RM2R4B5VrLwYXiNTwCXGzRHXUTBYYNS0qcljK7dotwQw1C5zSozc7mfBbWlEVD02MhTqVIwNVkGY26McOsQ7RUYnFp5UDBoepgUERrMyHxb57Low
重新登录地址
部署CoreDNS
coreDNS用于集群内部Service名称解析
[root@k8s-master01 k8s]# kubectl apply -f coredns.yaml
serviceaccount/coredns unchanged ##你们的应该是created,我这边是之前apply过了,所以会是这个
clusterrole.rbac.authorization.k8s.io/system:coredns unchanged
clusterrolebinding.rbac.authorization.k8s.io/system:coredns unchanged
configmap/coredns unchanged
deployment.apps/coredns created
service/kube-dns unchanged
[root@k8s-master01 k8s]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-97769f7c7-hwgnf 1/1 Running 0 11h
calico-node-grcgk 1/1 Running 0 11h
calico-node-zdfjw 1/1 Running 0 10h
coredns-6d8f96d957-mnx7d 1/1 Running 0 31s
DNS解析测试
[root@k8s-master01 k8s]# kubectl run -it --rm dns-test --image=busybox:1.28.4 sh
If you don't see a command prompt, try pressing enter.
Error attaching, falling back to logs: error dialing backend: dial tcp: lookup **k8s-master1** on 192.168.100.2:53: no such host
pod "dns-test" deleted ######发现出现问题
Error from server: Get "https://k8s-master1:10250/containerLogs/default/dns-test/dns-test": dial tcp: lookup k8s-master1 on 192.168.100.2:53: no such host
[root@k8s-master01 k8s]# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master1 Ready <none> 11h v1.20.5
k8s-node01 Ready <none> 10h v1.20.5
[root@k8s-master01 k8s]# vim /etc/hosts
##全部节点都要修改,如果在配置基础环境的时候,这个已经配置了,请省略这步
[root@k8s-master01 k8s]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.100.13 k8s-master1 ####将他改成master1
192.168.100.14 k8s-node01
192.168.100.15 k8s-node02
##全部节点都要修改,如果在配置基础环境的时候,这个已经配置了,请省略这步
[root@k8s-node01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.100.13 k8s-master1
192.168.100.14 k8s-node01
192.168.100.15 k8s-node02
重启一下kube-proxy,发现报下图错误,原因是缺少 conntrack,yum安装即可
[root@k8s-master01 k8s]# yum -y install conntrack
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.njupt.edu.cn
* extras: mirrors.njupt.edu.cn
* updates: mirrors.njupt.edu.cn
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 conntrack-tools.x86_64.0.1.4.4-7.el7 将被 安装
--> 正在处理依赖关系 libnetfilter_cttimeout.so.1(LIBNETFILTER_CTTIMEOUT_1.1)(64bit),它被软件包 conntrack-tools-1.4.4-7.el7.x86_64 需要
--> 正在处理依赖关系 libnetfilter_cttimeout.so.1(LIBNETFILTER_CTTIMEOUT_1.0)(64bit),它被软件包 conntrack-tools-1.4.4-7.el7.x86_64 需要
--> 正在处理依赖关系 libnetfilter_cthelper.so.0(LIBNETFILTER_CTHELPER_1.0)(64bit),它被软件包 conntrack-tools-1.4.4-7.el7.x86_64 需要
--> 正在处理依赖关系 libnetfilter_queue.so.1()(64bit),它被软件包 conntrack-tools-1.4.4-7.el7.x86_64 需要
--> 正在处理依赖关系 libnetfilter_cttimeout.so.1()(64bit),它被软件包 conntrack-tools-1.4.4-7.el7.x86_64 需要
--> 正在处理依赖关系 libnetfilter_cthelper.so.0()(64bit),它被软件包 conntrack-tools-1.4.4-7.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libnetfilter_cthelper.x86_64.0.1.0.0-11.el7 将被 安装
---> 软件包 libnetfilter_cttimeout.x86_64.0.1.0.0-7.el7 将被 安装
---> 软件包 libnetfilter_queue.x86_64.0.1.0.2-2.el7_2 将被 安装
--> 解决依赖关系完成
依赖关系解决
=================================================================================================================================================
Package 架构 版本 源 大小
=================================================================================================================================================
正在安装:
conntrack-tools x86_64 1.4.4-7.el7 base 187 k
为依赖而安装:
libnetfilter_cthelper x86_64 1.0.0-11.el7 base 18 k
libnetfilter_cttimeout x86_64 1.0.0-7.el7 base 18 k
libnetfilter_queue x86_64 1.0.2-2.el7_2 base 23 k
事务概要
=================================================================================================================================================
安装 1 软件包 (+3 依赖软件包)
总下载量:245 k
安装大小:668 k
Downloading packages:
(1/4): libnetfilter_cthelper-1.0.0-11.el7.x86_64.rpm | 18 kB 00:00:00
(2/4): libnetfilter_cttimeout-1.0.0-7.el7.x86_64.rpm | 18 kB 00:00:00
(3/4): libnetfilter_queue-1.0.2-2.el7_2.x86_64.rpm | 23 kB 00:00:00
(4/4): conntrack-tools-1.4.4-7.el7.x86_64.rpm | 187 kB 00:00:00
-------------------------------------------------------------------------------------------------------------------------------------------------
总计 285 kB/s | 245 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : libnetfilter_queue-1.0.2-2.el7_2.x86_64 1/4
正在安装 : libnetfilter_cthelper-1.0.0-11.el7.x86_64 2/4
正在安装 : libnetfilter_cttimeout-1.0.0-7.el7.x86_64 3/4
正在安装 : conntrack-tools-1.4.4-7.el7.x86_64 4/4
验证中 : libnetfilter_cttimeout-1.0.0-7.el7.x86_64 1/4
验证中 : libnetfilter_cthelper-1.0.0-11.el7.x86_64 2/4
验证中 : conntrack-tools-1.4.4-7.el7.x86_64 3/4
验证中 : libnetfilter_queue-1.0.2-2.el7_2.x86_64 4/4
已安装:
conntrack-tools.x86_64 0:1.4.4-7.el7
作为依赖被安装:
libnetfilter_cthelper.x86_64 0:1.0.0-11.el7 libnetfilter_cttimeout.x86_64 0:1.0.0-7.el7 libnetfilter_queue.x86_64 0:1.0.2-2.el7_2
完毕!
[root@k8s-master01 k8s]# systemctl restart kube-proxy
[root@k8s-master01 k8s]# systemctl status kube-proxy
● kube-proxy.service - Kubernetes Proxy
Loaded: loaded (/usr/lib/systemd/system/kube-proxy.service; enabled; vendor preset: disabled)
Active: active (running) since 三 2021-11-17 11:51:40 CST; 4s ago
Main PID: 20630 (kube-proxy)
Tasks: 6
Memory: 15.3M
CGroup: /system.slice/kube-proxy.service
└─20630 /opt/kubernetes/bin/kube-proxy --logtostderr=false --v=2 --log-dir=/opt/kubernetes/logs --config=/opt/kubernetes/cfg/kube-p...
11月 17 11:51:40 k8s-master01 systemd[1]: Started Kubernetes Proxy.
删除dns的pod,让其自动重拉
[root@k8s-master01 k8s]# kubectl delete pod coredns-6d8f96d957-mnx7d -n kube-system
pod "coredns-6d8f96d957-mnx7d" deleted
#### 依然无法启动
[root@k8s-master01 k8s]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-97769f7c7-hwgnf 1/1 Running 0 12h
calico-node-grcgk 1/1 Running 0 12h
calico-node-zdfjw 1/1 Running 0 11h
coredns-6d8f96d957-w4qt2 0/1 CrashLoopBackOff 7 13m
#### 查看日志
[root@k8s-master01 k8s]# kubectl logs coredns-6d8f96d957-w4qt2 -n kube-system
.:53
2021/11/17 04:18:49 [INFO] CoreDNS-1.2.2
2021/11/17 04:18:49 [INFO] linux/amd64, go1.11, eb51e8b
CoreDNS-1.2.2
linux/amd64, go1.11, eb51e8b
2021/11/17 04:18:49 [INFO] plugin/reload: Running configuration MD5 = 18863a4483c30117a60ae2332bab9448
2021/11/17 04:18:55 [FATAL] plugin/loop: Seen "HINFO IN 4649412549425110720.5759411566388094007." more than twice, loop detected ###lop发生了死循环,这个是loop再进行循环检测的时候,发现是自己本机的ip,就会出现这个报错
###解决方法,删除loop
[root@k8s-master01 k8s]# kubectl edit cm coredns -n kube-system ###执行这个命令后会打开coredns的配置文件,找到loop这行,将其删除(vim操作),不让他loop循环监听
configmap/coredns edited
[root@k8s-master01 k8s]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-97769f7c7-hwgnf 1/1 Running 0 12h
calico-node-grcgk 1/1 Running 0 12h
calico-node-zdfjw 1/1 Running 0 11h
coredns-6d8f96d957-w4qt2 0/1 CrashLoopBackOff 7 13m
[root@k8s-master01 k8s]# kubectl delete pod coredns-6d8f96d957-w4qt2^C-n kube-system ##删除pod,让他重拉
[root@k8s-master01 k8s]# vim /etc/resolv.conf
[root@k8s-master01 k8s]# kubectl delete pod coredns-6d8f96d957-w4qt2 -n kube-system
pod "coredns-6d8f96d957-w4qt2" deleted
[root@k8s-master01 k8s]# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-97769f7c7-hwgnf 1/1 Running 0 12h
calico-node-grcgk 1/1 Running 0 12h
calico-node-zdfjw 1/1 Running 0 11h
coredns-6d8f96d957-k5tfh 1/1 Running 0 10s
再次DNS解析测试
[root@k8s-master01 k8s]# kubectl run -it --rm dns-test --image=busybox:1.28.4 sh
If you don't see a command prompt, try pressing enter.
/ # nslookup kubernetes
Server: 10.0.0.2
Address 1: 10.0.0.2 kube-dns.kube-system.svc.cluster.local
Name: kubernetes
Address 1: 10.0.0.1 kubernetes.default.svc.cluster.local
/ # exit
Session ended, resume using 'kubectl attach dns-test -c dns-test -i -t' command when the pod is running
pod "dns-test" deleted
测试通过,dns部署成功
结束语
加油和坚持,相信自己一定会成功
上一篇:kubernetes v1.20项目之二进制安装部署Worker Node(亲测)
下一篇:kubernetes v1.20项目之二进制扩容多Master
更多推荐
已为社区贡献10条内容
所有评论(0)