I am deployed coredns in kubernetes cluster, but the mysql pod(ip:10.244.8.43) in the slave node is not using coredns ip as name server, I login to mysql pods and find the nameserver:
root@apollo-mysql-85fd475fc9-sjfhg:/# cat /etc/resolv.conf
nameserver 10.96.0.10
search sre.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
but the coredns (v1.6.7) pod's ip is: 10.244.6.34
, where is the problem? what should I do to make coredns work to my cluster pods? and this is my pod define :
kind: Deployment
apiVersion: apps/v1
metadata:
name: apollo-mysql
namespace: sre
selfLink: /apis/apps/v1/namespaces/sre/deployments/apollo-mysql
uid: b7a2f852-894d-4686-816c-21737535dbea
resourceVersion: '498210'
generation: 42
creationTimestamp: '2020-05-30T11:27:09Z'
annotations:
deployment.kubernetes.io/revision: '4'
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"apollo-mysql","namespace":"sre"},"spec":{"selector":{"matchLabels":{"app":"apollo-mysql"}},"strategy":{"type":"Recreate"},"template":{"metadata":{"labels":{"app":"apollo-mysql"}},"spec":{"containers":[{"env":[{"name":"MYSQL_ROOT_PASSWORD","value":"gl4LucnXwLeLwAd29QqJn4"}],"image":"mysql:5.7","name":"mysql","ports":[{"containerPort":3306,"name":"mysql"}],"volumeMounts":[{"mountPath":"/var/lib/mysql","name":"apollo-mysql-persistent-storage"}]}],"volumes":[{"name":"apollo-mysql-persistent-storage","persistentVolumeClaim":{"claimName":"apollo-mysql-pv-claim"}}]}}}}
spec:
replicas: 1
selector:
matchLabels:
app: apollo-mysql
template:
metadata:
creationTimestamp: null
labels:
app: apollo-mysql
spec:
volumes:
- name: apollo-mysql-persistent-storage
persistentVolumeClaim:
claimName: apollo-mysql-pv-claim
containers:
- name: mysql
image: 'mysql:5.7'
ports:
- name: mysql
containerPort: 3306
protocol: TCP
env:
- name: MYSQL_ROOT_PASSWORD
value: gl4LucnXwLeLwAd29QqJn4
resources: {}
volumeMounts:
- name: apollo-mysql-persistent-storage
mountPath: /var/lib/mysql
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: Recreate
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
status:
observedGeneration: 42
replicas: 1
updatedReplicas: 1
readyReplicas: 1
availableReplicas: 1
conditions:
- type: Progressing
status: 'True'
lastUpdateTime: '2020-05-31T03:34:11Z'
lastTransitionTime: '2020-05-30T11:38:19Z'
reason: NewReplicaSetAvailable
message: ReplicaSet "apollo-mysql-5f5c49c448" has successfully progressed.
- type: Available
status: 'True'
lastUpdateTime: '2020-05-31T08:34:56Z'
lastTransitionTime: '2020-05-31T08:34:56Z'
reason: MinimumReplicasAvailable
message: Deployment has minimum availability.
10.96.0.10
is commonly used as the IP for the kube-dns
service which is provided by the coredns
pods.
$ kubectl describe svc kube-dns -n kube-system
Name: kube-dns
...
Type: ClusterIP
IP: 10.96.0.10
Port: dns 53/UDP
TargetPort: 53/UDP
Endpoints: 192.168.150.144:53,192.168.24.204:53
...
So I think your coredns is being used. Check the IPs on the core-dns pods to be sure that the IPs line up:
$ kubectl describe pod -n kube-system coredns-....-.... | grep IP
IP: 192.168.150.144
Notice in my case the 192.168.150.144
is the pod IP of a coredns pod and it is listed in the service endpoints.
When we spin up a pod on Kubernetes Kubelet writes kube-dns service IP (not pod IP) in container's /etc/resolv.conf
file.
kubectl get svc -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 29d