018.Kubernetes二进制部署插件coredns
程序员文章站
2022-07-01 15:57:57
一 修改配置文件 1.1 下载解压 1 [root@k8smaster01 ~]# cd /opt/k8s/work/kubernetes/ 2 [root@k8smaster01 kubernetes]# tar -xzvf kubernetes-src.tar.gz 提示:k8smaster01 ......
一 修改配置文件
1.1 下载解压
1 [root@k8smaster01 ~]# cd /opt/k8s/work/kubernetes/ 2 [root@k8smaster01 kubernetes]# tar -xzvf kubernetes-src.tar.gz
提示:k8smaster01节点已解压完毕,可直接修改配置。
1.2 修改配置
1 [root@k8smaster01 ~]# cd /opt/k8s/work/kubernetes/cluster/addons/dns/coredns 2 [root@k8smaster01 coredns]# cp coredns.yaml.base coredns.yaml 3 [root@k8smaster01 coredns]# source /opt/k8s/bin/environment.sh 4 [root@k8smaster01 coredns]# sed -i -e "s/__pillar__dns__domain__/${cluster_dns_domain}/" -e "s/__pillar__dns__server__/${cluster_dns_svc_ip}/" coredns.yaml 5 [root@k8smaster01 coredns]# vi coredns.yaml 6 …… 7 image: registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1 8 …… 9 #修改image的源。
二 创建 coredns
2.1 创建coredns并检查
1 [root@k8smaster01 coredns]# kubectl create -f coredns.yaml
2.2 检查 coredns 功能
1 [root@k8smaster01 coredns]# kubectl get all -n kube-system
三 确认验证
3.1 新建deployment
1 [root@k8smaster01 ~]# cd /opt/k8s/work 2 [root@k8smaster01 work]# cat > my-nginx.yaml <<eof 3 apiversion: extensions/v1beta1 4 kind: deployment 5 metadata: 6 name: my-nginx 7 spec: 8 replicas: 2 9 template: 10 metadata: 11 labels: 12 run: my-nginx 13 spec: 14 containers: 15 - name: my-nginx 16 image: nginx:1.7.9 17 ports: 18 - containerport: 80 19 eof
3.2 export该deployment
1 [root@k8smaster01 work]# kubectl expose deploy my-nginx
3.3 查看该service
1 [root@k8smaster01 work]# kubectl get services --all-namespaces | grep my-nginx 2 default my-nginx clusterip 10.254.157.163 <none> 80/tcp 9s 3
3.4 创建另一个pod
1 [root@k8smaster01 ~]# cd /opt/k8s/work 2 [root@k8smaster01 work]# cat > dnsutils-ds.yml <<eof 3 apiversion: v1 4 kind: service 5 metadata: 6 name: dnsutils-ds 7 labels: 8 app: dnsutils-ds 9 spec: 10 type: nodeport 11 selector: 12 app: dnsutils-ds 13 ports: 14 - name: http 15 port: 80 16 targetport: 80 17 --- 18 apiversion: extensions/v1beta1 19 kind: daemonset 20 metadata: 21 name: dnsutils-ds 22 labels: 23 addonmanager.kubernetes.io/mode: reconcile 24 spec: 25 template: 26 metadata: 27 labels: 28 app: dnsutils-ds 29 spec: 30 containers: 31 - name: my-dnsutils 32 image: tutum/dnsutils:latest 33 command: 34 - sleep 35 - "3600" 36 ports: 37 - containerport: 80 38 eof 39 [root@k8smaster01 work]# kubectl create -f dnsutils-ds.yml 40 [root@k8smaster01 work]# kubectl get pods -lapp=dnsutils-ds
3.5 检查解析
1 [root@k8smaster01 ~]# kubectl create clusterrolebinding kube-apiserver:kubelet-apis --clusterrole=system:kubelet-api-admin --user kubernetes 2 [root@k8smaster01 ~]# kubectl -it exec dnsutils-ds-4f2nt bash 3 root@dnsutils-ds-4f2nt:/# cat /etc/resolv.conf 4 nameserver 10.254.0.2 5 search default.svc.cluster.local svc.cluster.local cluster.local 6 options ndots:5 7 8 [root@k8smaster01 work]# kubectl exec dnsutils-ds-4f2nt nslookup kubernetes 9 [root@k8smaster01 work]# kubectl exec dnsutils-ds-4f2nt nslookup www.baidu.com 10 [root@k8smaster01 work]# kubectl exec dnsutils-ds-4f2nt nslookup my-nginx 11 [root@k8smaster01 work]# kubectl exec dnsutils-ds-4f2nt nslookup kube-dns.kube-system.svc 12 [root@k8smaster01 work]# kubectl exec dnsutils-ds-4f2nt nslookup kube-dns.kube-system.svc.cluster.local 13 [root@k8smaster01 work]# kubectl exec dnsutils-ds-4f2nt nslookup kube-dns.kube-system.svc.cluster.local.