安装k8s coreDns

创建目录下载coreDns:

mkdir coredns && cd coredns
wget https://github.com/coredns/deployment/blob/master/kubernetes/deploy.sh
wget https://github.com/coredns/deployment/blob/master/kubernetes/coredns.yaml.sed

部署coreDns

# 10.254.0.2 dnsclusterIp  test.com当前域名
# yum -y install jq
# ./deploy.sh -i 10.254.0.2 -d test.com > coredns.yaml

# kubectl apply -f coredns.yaml
serviceaccount/coredns created
clusterrole.rbac.authorization.k8s.io/system:coredns created
clusterrolebinding.rbac.authorization.k8s.io/system:coredns created
configmap/coredns created
deployment.apps/coredns created
service/kube-dns created

# 查看
kubectl get pods --namespace kube-system
kubectl get svc --namespace kube-system

验证coreDns

# 验证
# kubectl run cirros-$RANDOM --rm -it --image=cirros -- sh
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.

/ # nslookup www.163.com
Server:    10.254.0.2
Address 1: 10.254.0.2 kube-dns.kube-system.svc.shuyuan.com

Name:      www.163.com
Address 1: 2408:8778:180:100:0:1:1:c
Address 2: 175.153.175.199
Address 3: 175.153.175.195
Address 4: 175.153.175.201
Address 5: 175.153.175.197
Address 6: 175.153.175.200
Address 7: 175.153.175.196
Address 8: 175.153.175.194

/ # ping nginx-web
PING nginx-web (10.254.47.180): 56 data bytes
64 bytes from 10.254.47.180: seq=0 ttl=64 time=0.047 ms
64 bytes from 10.254.47.180: seq=1 ttl=64 time=0.059 ms
64 bytes from 10.254.47.180: seq=2 ttl=64 time=0.066 ms

/ # ping www.163.com
PING www.163.com (175.153.175.195): 56 data bytes
64 bytes from 175.153.175.195: seq=0 ttl=53 time=5.052 ms
64 bytes from 175.153.175.195: seq=1 ttl=53 time=3.325 ms

/ # cat /etc/resolv.conf 
nameserver 10.254.0.2
search default.svc.test.com. svc.test.com. test.com. .test.com
options ndots:5

发表评论

电子邮件地址不会被公开。 必填项已用*标注