k8s v1.14 dns插件

部署 coredns 插件

注意:

  • kuberntes 自带插件的 manifests yaml 文件使用 gcr.io 的 docker registry,国内被墙,需要手动替换为其它 registry 地址;

修改配置文件

将下载的 kubernetes-server-linux-amd64.tar.gz 解压后,再解压其中的 kubernetes-src.tar.gz 文件。

1
2
# cd kubernetes
# tar -xzvf kubernetes-src.tar.gz
  • coredns 目录是 cluster/addons/dns
    1
    2
    3
    4
    5
    # cd cluster/addons/dns/coredns
    # cp coredns.yaml.base coredns.yaml
    # sed -i -e "s/__PILLAR__DNS__DOMAIN__/cluster.local/" -e "s/__PILLAR__DNS__SERVER__/10.254.0.2/" coredns.yaml
    # sed -i "s/k8s.gcr.io/coredns/" coredns.yaml
    # kubectl create -f coredns.yaml

检查 coredns 功能

1
2
3
4
5
6
7
8
9
10
11
12
# kubectl get all -n kube-system
NAME READY STATUS RESTARTS AGE
pod/coredns-5579b8778b-xw8m9 1/1 Running 1 5h7m

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kube-dns ClusterIP 10.254.0.2 <none> 53/UDP,53/TCP,9153/TCP 5h7m

NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/coredns 1/1 1 1 5h7m

NAME DESIRED CURRENT READY AGE
replicaset.apps/coredns-5579b8778b 1 1 1 5h7m

验证

1
2
3
4
5
# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-ds-9fb46 1/1 Running 0 5h14m
nginx-ds-bgfzt 1/1 Running 0 5h14m
nginx-ds-t22wj 1/1 Running 0 5h14m
1
2
3
4
5
6
7
8
9
10
11
12
13
# kubectl -it exec nginx-ds-9fb46 bash
root@nginx-ds-9fb46:/# cat /etc/resolv.conf
nameserver 10.254.0.2
search default.svc.cluster.local svc.cluster.local cluster.local openstacklocal novalocal
options ndots:5

root@nginx-ds-9fb46:/# ping www.baidu.com
PING www.wshifen.com (104.193.88.77): 48 data bytes
56 bytes from 104.193.88.77: icmp_seq=0 ttl=45 time=191.953 ms
56 bytes from 104.193.88.77: icmp_seq=1 ttl=45 time=191.680 ms
^C--- www.wshifen.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 191.680/191.817/191.953/0.137 ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root@nginx-ds-9fb46:/# ping kube-dns.kube-system.svc
PING kube-dns.kube-system.svc.cluster.local (10.254.0.2): 48 data bytes
56 bytes from 10.254.0.2: icmp_seq=0 ttl=64 time=0.120 ms
56 bytes from 10.254.0.2: icmp_seq=1 ttl=64 time=0.116 ms
^C--- kube-dns.kube-system.svc.cluster.local ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.116/0.118/0.120/0.000 ms

root@nginx-ds-9fb46:/# ping kube-dns.kube-system.svc.cluster.local
PING kube-dns.kube-system.svc.cluster.local (10.254.0.2): 48 data bytes
56 bytes from 10.254.0.2: icmp_seq=0 ttl=64 time=0.079 ms
56 bytes from 10.254.0.2: icmp_seq=1 ttl=64 time=0.152 ms
^C--- kube-dns.kube-system.svc.cluster.local ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.079/0.115/0.152/0.037 ms

root@nginx-ds-9fb46:/# ping kube-dns.kube-system.svc.cluster.local.
PING kube-dns.kube-system.svc.cluster.local (10.254.0.2): 48 data bytes
56 bytes from 10.254.0.2: icmp_seq=0 ttl=64 time=0.080 ms
^C--- kube-dns.kube-system.svc.cluster.local ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.080/0.080/0.080/0.000 ms
`
坚持原创技术分享,您的支持将鼓励我继续创作!
0%