K8s 中的 Dns 问题

1. 检查本机的 dns 配置

1
2
3
4
5
6
7
8
9
# 建议不要配置 search,除非你自己明确, 可用的 dns 域名,如 8.8.8.8
# 修改后,centos系统不需要重启 NetworkManager, 重启可能被覆盖
cat /etc/resolv.conf

# 重启 kubelet
systemctl restart kubelet

# 重启 k8s pod
kubectl rollout restart deploy

2. 检查 pod 的 dns 配置

1
2
3
4
5
6
7
8
# 进入容器中
kubectl debug -it some-pod --image=busybox -- sh

# 在容器中查看 dns 配置, 这里一定要是 coredns 的 clusterIP, 如果不对,检查 kubelet 的 dns 配置
cat /etc/resolv.conf

# 在容器中查看 hosts 配置
cat /etc/hosts

3. 检查并配置 coredns 配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 检查配置
kubectl get cm coredns -n kube-system -oyaml

# 自定义配置,如添加 hosts 配置
kubectl apply -f - <<EOF
apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health {
           lameduck 5s
        }
        ready
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           fallthrough in-addr.arpa ip6.arpa
           ttl 30
        }
        prometheus :9153
        # 添加 hosts 配置
        hosts {
            172.16.1.36 git.abc.com
            fallthrough
        }
        # 不转发到 /etc/resolv.conf
        forward . 8.8.8.8
        cache 30
        loop
        reload
        loadbalance
    }
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
EOF

4. 问题现象

tektonpod dns 显示错误,重新设置主机的 /etc/resolv.conf, 重启 kubelet, 重启 tekton.

Ubuntu Add Static Ip

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# open target dir
cd /etc/netplan

# edit config file, you must creat if not exist
sudo vim 00-installer-config.yaml

# network device setting template
network:
  ethernets:
    ens33:
      #dhcp4: yes
      dhcp4: no
      addresses:
        - 192.168.130.129/24
      routes:
        - to: default
          via: 192.168.130.2

      #nameservers:
      #  addresses: [192.168.130.2]
  version: 2
  
# netplan apply 
sudo netplan apply

# restart 
reboot 

Docker 设置镜像源

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
vim /etc/docker/daemon.json

# 添加以下配置
{
  "registry-mirrors": [
    "https://hub-mirror.c.163.com",
    "https://mirror.baidubce.com"
  ]
}

# 重启docker
sudo systemctl daemon-reload
sudo systemctl restart docker