CoreDNS Plugins ---> hosts
需求
kubernetes集群外部有少量服务,kubernetes集群内部pod需要通过服务所在的主机的hostname访问服务。
解决方案
通过coredns的hosts插件配置kubernetes集群的dns服务,使集群内部可通过hostname/域名访问外部服务。
参考:CoreDNS hosts
hosts插件格式
hosts [FILE [ZONES...]] {
[INLINE]
fallthrough [ZONES...]
}
- FILE:需要读取与解析的hosts文件;如果省略,默认取值"/etc/hosts";每5s扫描一次hosts文件的变更。
- ZONES:如果为空,取配置块中的zone。
- INLINE:宿主机hosts文件在corefile中的内联;在"fallthrough"之前的所有"INLINE"都可视为hosts文件的附加内容,hosts文件中相同条目将被覆盖,以"INLINE"为准。
- fallthrough:如果zone匹配且无法生成记录,将请求传递给下一个插件;如果省略,对所有zones有效,如果列出特定zone,则只有列出的zone受到影响。
范例
以Kubernetes采用CoreDNS中的coredns-cm.yaml为基础变更,如下:
cat coredns-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
labels:
addonmanager.kubernetes.io/mode: EnsureExists
data:
Corefile: |
.:53 {
errors
health
# 省略了”FILE“,"ZONES"等字段
hosts {
# 1个hostname映射1个ip;
# 虽然格式"172.30.200.21 172.30.200.22 172.30.200.23 kubenode1"可以正常下发configmap资源,但只有第一个ip生效
172.30.200.21 kubenode1
172.30.200.22 kubenode2
172.30.200.23 kubenode3
fallthrough
}
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
upstream
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
proxy . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
验证
# 替换configmap
kubectl replace -f coredns-cm.yaml
# ping外部hostname
kubectl exec -it dnstest -- ping kubenode1
kubectl exec -it dnstest -- ping kubenode2
kubectl exec -it dnstest -- ping kubenode3

CoreDNS Plugins ---> hosts的更多相关文章
- coredns 编译模式添加插件
备注: coredns 默认已经安装了一些插件,比如大家用的多的kubernetes etcd ... 但是我们可以自己编译插件,构建我们自己的 coredns 版本,方便集成使用 1. 项目结 ...
- centos7快速安装coreDns
1.下载二进制文件 wget https://github.com/coredns/coredns/releases/download/v1.5.0/coredns_1.5.0_linux_amd64 ...
- docker部署coredns
示例: [root@corends coredns]# cd /home/coredns/ [root@corends coredns]# ls -al total drwxr-xr-x root r ...
- 让外部的开发机直接访问Kubernetes群集内的服务!
让外部的开发机直接访问Kubernetes群集内的服务! 1.场景 容器化+K8s编排已经是现在进行时把网站的多个项目设计为云原生(Cloud Native)或老项改造为云原生可以获得诸多能力例如无云 ...
- KubeSphere CI/CD+GitLab+Harbor将Spring Boot项目部署至Kubernetes
上一篇文章分享了如何在 KubeSphere 对公共的代码仓库 GitHub 和镜像仓库 DockerHub 创建流水线,本文将继续使用 KubeSphere,基于 Harbor 和 GitLab 创 ...
- WireGuard 教程:使用 DNS-SD 进行 NAT-to-NAT 穿透
原文链接:https://fuckcloudnative.io/posts/wireguard-endpoint-discovery-nat-traversal/ WireGuard 是由 Jason ...
- 一文读懂 SuperEdge 云边隧道
作者 李腾飞,腾讯容器技术研发工程师,腾讯云TKE后台研发,SuperEdge核心开发成员. 杜杨浩,腾讯云高级工程师,热衷于开源.容器和Kubernetes.目前主要从事镜像仓库,Kubernete ...
- Linux网络学习笔记(二):域名解析(DNS)——以 CoreDNS 为例
个人笔记,观点不一定正确. 适合对 Kubernetes 有一定了解的同学. 前言 最近一直在学习 Kubernetes,但是手头没有个自有域名,要测试 ingress 就比较麻烦,每次都是手动改 h ...
- 使用 CoreDNS 来应对 DNS 污染
原文链接:https://fuckcloudnative.io/posts/install-coredns-on-macos/ CoreDNS 是 Golang 编写的一个插件式 DNS 服务器,是 ...
随机推荐
- 匿名访问windows server 2008 R2 文件服务器的共享
匿名访问windows server 2008 R2 文件服务器的共享 匿名访问windows 2008 R2 文件服务器的共享,七步:第一步 取消简单文件共享:第二步 设置需要共享的文件夹every ...
- Mysql 5.7源码编译启动 报error问题:The server quit without updating PID file (/data/data_mysql/mysql.pid).
一般是报error问题就是我们的mysql没有权限,这里主要是指三点:一个是mysql的安装主目录要设为mysql用户和用户组.一个是logs目录设置为mysql用户以及用户组.还有一个是data目录 ...
- October 13th 2017 Week 41st Friday
The shortest distance between two people is a smile. 人与人之间最短的距离是微笑. I find a smiling face can bring ...
- PHP中全局变量global和$GLOBALS[]的区别分析
$GLOBALS['var']是外部的全局变量本身,global $var是外部$var的同名引用或者指针 一.举例比较 例一: 复制代码 代码如下: <?php $var1 = 1; ...
- php 去除数组中指定的值
方法1: //去除值为"Cat"的元素 $a=array("a"=>"Dog","b"=>"Cat ...
- OC4J Configuration issue. /u01...dbhome_1/oc4j/j2ee/OC4J_DBConsole_orcl-db-01_orcl not found.
emctl start dbconsole 报错信息: OC4J Configuration issue. /u01/app/Oracle/product/11.2.0/dbhome_1/oc4j/j ...
- 根据Uri获取文件的绝对路径
简易版处理(实际并没发现有什么问题) public static String getRealPathFromURI(Context context, Uri contentURI) { String ...
- android 7.0拍照问题file:///storage/emulated/0/photo.jpeg exposed beyond app through ClipData.Item.getUri
Android7.0调用相机时出现新的错误: android.os.FileUriExposedException: file:///storage/emulated/0/photo.jpeg exp ...
- Python2.7-内置异常类型
python内置了许多异常类型,他们的继承关系如下:-----------------------------------------------BaseException +-- SystemExi ...
- windows安装wget
windows安装wget1. 下载wget-1.11.4-1-setup.exehttps://jaist.dl.sourceforge.net/project/gnuwin32/wget/1.11 ...