gpt4 book ai didi

kubernetes - 如何在Kubernetes 1.14版上启用coredns进行DNS查找?

转载 作者:行者123 更新时间:2023-12-02 12:16:25 25 4
gpt4 key购买 nike

我在 ubuntu仿生 kubernetes 1.14 版本中发现服务(DNS)时遇到问题。
现在,我的两个Pod正在使用IP地址进行通信。如何启用 coredns 进行服务(DNS)发现?
这是kube-system namespace 中用于服务和pod的kubectl的输出:


kubectl get pods,svc --namespace=kube-system | grep dns
pod/coredns-fb8b8dccf-6plz2 1/1 Running 0 6d23h
pod/coredns-fb8b8dccf-thxh6 1/1 Running 0 6d23h

service/kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 6d23h

我已经使用以下步骤在主节点(ubuntu仿生机器)上安装了kubernetes

apt-get update
apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io
apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

apt-get update
apt-get install -y kubelet kubeadm kubectl
kubectl version
apt-mark hold kubelet kubeadm kubectl
kubeadm config images pull
swapoff -a
kubeadm init

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
sysctl net.bridge.bridge-nf-call-iptables=1
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
kubectl get pods --all-namespaces

这是在工作节点上
    Docker is already installed, so directly installing kubernetes on worker node
apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

apt-get update
apt-get install -y kubelet kubeadm kubectl
kubectl version
apt-mark hold kubelet kubeadm kubectl
swapoff -a
Now joined worker node to master

回答:-
我认为默认情况下所有设置都正确设置,我有一个误解,就是我可以使用规范中指定的容器名称和端口来调用从另一个容器运行在另一个容器中的服务器,而应该使用服务名称和端口。
以下是我的部署规范和服务规范:-
部署规格:
    apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: node-server1-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: node-server1
spec:
hostname: node-server1
containers:
- name: node-server1
image: bvenkatr/node-server1:1
ports:
- containerPort: 5551
服务规格:
    kind: Service
apiVersion: v1
metadata:
name: node-server1-service
spec:
selector:
app: node-server1
ports:
- protocol: TCP
port: 5551

最佳答案

As of Kubernetes v1.12, CoreDNS is the recommended DNS Server, replacing kube-dns. In Kubernetes, CoreDNS is installed with the following default Corefile configuration:


apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.:53 {
errors
health
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
}

您可以找到 here的更多信息。

您可以通过运行以下命令来验证环境:
kubectl get cm coredns -n kube-system -o yaml

apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system

和:
kubeadm配置 View
DNS:
类型:CoreDNS

在kubeadm初始化期间,您应该注意到:
[addons] Applied essential addon: CoreDNS

如果您要从kube-dns迁移到CoreDNS,请确保在升级期间将CoreDNS feature gate设置为 true 。例如,这是v1.11.0升级的样子: kubeadm upgrade apply v1.11.0 --feature-gates=CoreDNS=true

In Kubernetes version 1.13 and later the CoreDNS feature gate is removed and CoreDNS is used by default. More information here.



您可以通过运行以下命令来查看您的coredns pod是否正常运行:
kubectl logs <your coredns pod> -n kube-system
.:53
2019-05-02T13:32:41.438Z [INFO] CoreDNS-1.3.1
CoreDNS-1.3.1
.
.

关于kubernetes - 如何在Kubernetes 1.14版上启用coredns进行DNS查找?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55896462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com