第三课:部署Coredns服务

摘要:
9153/TCP3m8sk8s app=coredns12.3验证DNS是否有效12.3.1启动dntools容器kubectlrun it--rm--restart=Never--image=infoblox/dntools:Forbidden(用户=系统:

12. 部署DNS(master01)

12.1 部署coredns

mkdir -p /root/dns && cd /root/dns
kubectl create -f coredns.yaml

[root@master01 dns]# kubectl create -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.extensions/coredns created
service/coredns created
[root@master01 dns]# kubectl get pods
No resources found.
[root@master01 dns]# kubectl get pod -A
NAMESPACE     NAME                       READY   STATUS              RESTARTS   AGE
kube-system   coredns-66db855d4d-l2h66   0/1     ContainerCreating   0          13s


[root@master01 dns]# kubectl get pod -n kube-system
NAME                       READY   STATUS    RESTARTS   AGE
coredns-66db855d4d-l2h66   1/1     Running   0          116s

[root@master01 dns]# kubectl describe pod coredns-66db855d4d-l2h66 -n kube-system

12.2 查看svc

[root@master01 dns]#  kubectl get svc -o wide -n=kube-system
NAME      TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE    SELECTOR
coredns   ClusterIP   10.0.0.2     <none>        53/UDP,53/TCP,9153/TCP   3m8s   k8s-app=coredns

12.3 验证DNS是否有效

12.3.1 启动dnstools容器
kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools

[root@master01 config]# kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools
If you don't see a command prompt, try pressing enter.
Error attaching, falling back to logs: unable to upgrade connection: Forbidden (user=system:anonymous, verb=create, resource=nodes, subresource=proxy)
pod "dnstools" deleted
Error from server (Forbidden): Forbidden (user=system:anonymous, verb=get, resource=nodes, subresource=proxy) ( pods/log dnstools)

出现错误Error from server (Forbidden): Forbidden (user=system:anonymous, verb=get, resource=nodes, subresource=proxy) ( pods/log dnstools)的解决方法

kubectl create clusterrolebinding system:anonymous --clusterrole=cluster-admin --user=system:anonymous

[root@master01 config]# kubectl create clusterrolebinding system:anonymous --clusterrole=cluster-admin --user=system:anonymous
clusterrolebinding.rbac.authorization.k8s.io/system:anonymous created
重新创建dnstools
kubectl delete pod dnstools
kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools

创建成功可以测试dns解析
dns解析的是svc(service)的name,而不是pod的name。

dnstools# nslookup www.baidu.com
Server:         10.0.0.2
Address:        10.0.0.2#53

Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
Name:   www.a.shifen.com
Address: 61.135.169.121
Name:   www.a.shifen.com
Address: 61.135.169.125
Name:   www.a.shifen.com
Address: 2408:80f0:410c:1c::ff:b00e:347f
Name:   www.a.shifen.com
Address: 2408:80f0:410c:1d::ff:b07a:39af
12.3.2 创建nginx容器测试dns解析
kubectl run nginx --image=nginx --replicas=2
kubectl expose deployment nginx --port=88 --target-port=80 --type=NodePort
12.3.3 查看svc
kubectl get svc
[root@master01 ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP        11h
nginx        NodePort    10.0.0.156   <none>        88:31836/TCP   7s
12.3.4 测试解析nginx

通过我们安装的dns服务,可以解析同一个namespace下其他服务。
解析名规则:[SVC-name].[namespace].svc.clouster.local

dnstools# nslookup nginx
Server:         10.0.0.2
Address:        10.0.0.2#53

Name:   nginx.default.svc.cluster.local
Address: 10.0.0.156

免责声明:文章转载自《第三课:部署Coredns服务》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇vue-clipboard2的使用ASCII 非打印字符下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

DNS跳转

1 switch(window.location.hostname) { 2 case "www.zcom.gov.cn" ://确定域名为 www.zcom.gov.cn 3 //window.location.pathname="/"//跳转到 / 目录 4 break; 5 case "cisf.zco...

什么是Windows域

你可以把 域 ------公司 域控制器 ------公司制度(更形象的是公司大门的门禁系统) 计算机 ------每个人 工作组 -------没有门禁系统的公司   =================================== 在说域这个概念之前,我们先...

4G EPS 中的 PDN Connection

目录 文章目录 目录 前文列表 PDN PDN Connection APN APN 与 PGW POOL APN 与 vPGW APN 与漫游 PDN Type IP 类型 Non-IP 类型 MME 通过 S6a 查询 HSS 中的用户信息(APN、PDN Type) APN-NI 与 PDN Type 的匹配规则 UE 没有上报 APN...

Linux 下使用acme.sh生成Let's Encrypt泛域名免费证书

一、需求场景 自从数年前苹果开始强制要求所有IOS所有应用必须全部使用 https,以及google、baidu、bing 这三大搜索引擎开始大规模支持 https,https 已经成为现在保障网站完全的最基础需求,大量的供应商开始出现,并提供证书服务,但是对于一些非盈利性质的网站或博客站长,或公司测试环境也想使用https认证时,并不想在这上面投入太多的...

DNS解析过程和域名收敛、域名发散、SPDY应用

前段时间项目要做域名收敛,糊里糊涂的完成了,好多原理不清晰,现在整理搜集下知识点。 域名收敛的目的是什么?简单来说就是域名解析慢。那为什么解析慢?且听下文慢慢道来。 什么是DNS?  DNS( Domain Name System)是“域名系统”的英文缩写,是一种组织成域层次结构的计算机和网络服务命名系统,它用于TCP/IP网络,它所提供的服务是用来将主机...

DNS(BIND)服务搭建

一、DNS 1.负责将域名解析为IP(正向解析);将IP解析为域名(反向解析) 2.DNS查询过程 如客户端访问www.baidu.com 1)客户端查看本地是否存有DNS缓存 2)客户端查看本地hosts文件是否有域名对应IP地址 3)客户端向首选DNS服务器请求指定域名的IP地址,如果首选DNS本地缓存指定域名 4)首选DNS服务器向根(.)发送查询请...