Mar*_*cus 2 kubernetes kube-dns kubeadm
我想通过在我的DNS服务器上添加一个存根区域来解决kubernets集群外部的kube-dns名称。这需要将cluster.local域更改为适合我的DNS名称空间的内容。
群集dns与cluster.local正常工作。要更改域,我已使用/etc/systemd/system/kubelet.service.d/10-kubeadm.conf上的KUBELET_DNS_ARGS将该行修改为:
Environment="KUBELET_DNS_ARGS=--cluster-dns=x.y.z --cluster-domain=cluster.mydomain.local --resolv-conf=/etc/resolv.conf.kubernetes"
Run Code Online (Sandbox Code Playgroud)
重新启动kubelet后,外部名称可以解析,但kubernetes名称解析失败。
我可以看到kube-dns仍在运行:
/kube-dns --domain=cluster.local. --dns-port=10053 --config-dir=/kube-dns-config --v=2
Run Code Online (Sandbox Code Playgroud)
我唯一能找到cluster.local的地方是在pods yaml配置中,其内容为:
containers:
- args:
- --domain=cluster.local.
- --dns-port=10053
- --config-dir=/kube-dns-config
- --v=2
Run Code Online (Sandbox Code Playgroud)
修改yaml并使用来重新创建pod之后
kubectl replace --force -f kube-dns.yaml
Run Code Online (Sandbox Code Playgroud)
我仍然看到kube-dns从--domain = cluster.local开始。
我想念什么?
小智 8
我假设您正在使用 CoreDNS。
您可以通过编辑所有节点上的 kubelet 配置文件(位于此处)来更改集群基本 DNS,/var/lib/kubelet/config.yaml或者在kubeadm init.
改变
clusterDomain: cluster.local
Run Code Online (Sandbox Code Playgroud)
到:
clusterDomain: my.new.domain
Run Code Online (Sandbox Code Playgroud)
现在您还需要更改 CoreDNS 配置。CoreDNS 为此使用 ConfigMap。您可以通过运行获取当前的 CoreDNS ConfigMap
kubectl get -n kube-system cm/coredns -o yaml
Run Code Online (Sandbox Code Playgroud)
然后改变
kubernetes cluster.local in-addr.arpa ip6.arpa {
...
}
Run Code Online (Sandbox Code Playgroud)
像这样匹配您的新域名:
kubernetes my.new.domain in-addr.arpa ip6.arpa {
...
}
Run Code Online (Sandbox Code Playgroud)
现在将更改应用到 CoreDNS ConfigMap。如果您重新启动 kubelet 和 CoreDNS Pod,那么您的集群应该使用新域。
例如,如果您有一个名为grafana-service 的服务,现在可以使用以下地址访问它:
grafana-service.default.svc.my.new.domain
# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
grafana-service ClusterIP <Internal-IP> <none> 3000/TCP 100m
# nslookup grafana-service.default.svc.my.new.domain
Server: <Internal-IP>
Address 1: <Internal-IP> kube-dns.kube-system.svc.my.new.domain
Name: grafana-service.default.svc.my.new.domain
Address 1: <Internal-IP> grafana-service.default.svc.my.new.domain
Run Code Online (Sandbox Code Playgroud)
我一直在将基于微服务的应用程序移植到Kubernetes时遇到类似的问题。将内部DNS区域更改为cluster.local将是一项相当复杂的任务,我们实际上并不想处理。
在我们的案例中,我们从KubeDNS切换到CoreDNS,仅启用了coreDNS重写插件即可将转换our.internal.domain为ourNamespace.svc.cluster.local。
完成此操作后,我们的CoreDNS configmap的corefile部分看起来像这样:
data:
Corefile: |
.:53 {
errors
health
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
upstream
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
rewrite name substring our.internal.domain ourNamespace.svc.cluster.local
proxy . /etc/resolv.conf
cache 30
}
Run Code Online (Sandbox Code Playgroud)
这使我们的kubernetes服务可以在默认DNS区域和我们自己的区域上进行响应。
Jav*_*ron -3
当您修改 /etc/kubernetes/manifests/ yaml 文件时,您需要再次重新启动 kubelet。
此外,如果这不起作用,请仔细检查 kubelet 日志以查看是否正在加载正确的 yaml 文件。
| 归档时间: |
|
| 查看次数: |
3654 次 |
| 最近记录: |