DNS (domain Name System), which provides domain name resolution services, addresses difficult-to-remember IP address issues and maps corresponding IP addresses in a more human-readable and memorable way.
The Cluster DNS extension is used to support discovery and invocation between services in a k8s clustered system.
Component:
? SKYDNS provides DNS resolution service
? ETCD Storing DNS information
? Kube2sky Monitor Kubernetes, when a service is created, generate the corresponding record to Skydns.
The experimental environment of this article is consistent with the introduction of the K8S Series cluster installation article. Master (1) + node (4)
1. Modify all node's configuration files:/etc/kubernetes/kubelet
NODE1,NODE2,NODE3.NODE4:
[Email protected] ~]# tail-n 1/etc/kubernetes/kubelet
Kubelet_args="--cluster-dns=10.254.254.254--cluster-domain=cluster.local"
2. All node (NODE1,NODE2,NODE3,NODE4) restarts the Kubelet service
[Email protected] ~]# systemctl restart Kubelet.service
3. According to the namespace divided into different namespaces, the system services unified into a separate space: Kube-system, because the default space is only defaulted, we first want to create Kube-system space.
[email protected] skydns]# cat Kube-system.yml
apiVersion:v1kind:Namespacemetadata: Name:kub-system
4. Edit the Replicationcontroller file on the master server Skydns-rc.yml
[email protected] skydns]# cat Skydns-rc.yml
ApiVersion:v1kind:ReplicationControllermetadata:name:kube-dns-v11 Namespace:kube-system labels:k8s-app:kube-DNS version:v11 Kubernetes.io/cluster-service:"true"Spec:replicas:1selector:k8s-app:kube-DNS version:v11 template:metadata:labels:k8s-app:kube-DNS version:v11 Kubernetes.io/cluster-service:"true"spec:containers:-NAME:ETCD image:docker.gaoxiaobang.com/KUBERNETES/ETCD-AMD64:2.2.1resources:limits:cpu:100m memory:500mi requests:cpu: 100m memory:50mi command:-/usr/local/bin/Etcd--data-dir-/var/etcd/Data--listen-client-URLs-http://127.0.0.1:2379,http://127.0.0.1: 4001--advertise-client-URLs-http://127.0.0.1:2379,http://127.0.0.1: 4001--initial-cluster-token-skydns-etcd #volumeMounts: #-name:etcd-Storage # Mountpath:/var/etcd/Data-Name:kube2sky image:docker.gaoxiaobang.com/kubernetes/kube2sky:1.14args: # command="/kube2sky"---domain=cluster.local---kube-master-url=http://192.168.30.20:8080resources:limits:cpu:100m memory:200mi requests:cpu:1 00m memory:50mi-Name:skydns image:docker.gaoxiaobang.com/kubernetes/skydns: --Ten- --8c72f8c resources:limits:cpu:100m memory:200mi requests: cpu:100m memory:50mi args:--machines=http://127.0.0.1:4001--addr=0.0.0.0: ---ns-rotate=false--domain=cluster.local. Ports:-Containerport: -Name:dns protocol:udp-Containerport: -Name:dns-TCP protocol:tcp LivenessProbe:httpGet:path:/Healthz Port:8080scheme:http initialdelayseconds: -timeoutseconds:5Successthreshold:1FailureThreshold:5ReadinessProbe:httpGet:path:/Readiness Port:8080scheme:http initialdelayseconds: -timeoutseconds:5-Name:healthz image:docker.gaoxiaobang.com/kubernetes/exechealthz:1.0resources:limits:cpu:10m memory:20mi requests:cpu:10m Memory:20mi args:--cmd=nslookup kubernetes.default.svc.cluster.local localhost >/dev/NULL--port=8080Ports:-Containerport:8080protocol:tcp Volumes:-name:etcd-storage emptydir: {} dnspolicy:default
5. Create the Skydns service file on Master Skydns-svc.yml
[email protected] skydns]# cat Skydns-svc.yml
ApiVersion:v1kind:Servicemetadata:name:kube-DNS Namespace:kube-system labels:k8s-app:kube-DNS Kubernetes.io/cluster-service:"true"Kubernetes.io/name:"Kubedns"spec:selector:k8s-app:kube-DNS Clusterip:10.254.254.254Ports:-Name:dns Port: -protocol:udp-name:dns-TCP port: -protocol:tcp
6. Create a Cluster-dns analytic application in the cluster
? Create namespace
[Email protected] skydns]# Kubectl create-f kube-system.yml
? Create Replicationcontroller
[Email protected] skydns]# Kubectl create-f skydns-rc.yml
? Create service
[Email protected] skydns]# Kubectl create-f skydns-svc.yml
7. Look at the boot status of the pod defined in the Skydns-rc.yml file, and the following will start successfully.
[[email protected] skydns]# kubectl get pod--namespace=kube-systemNAME ready STATUS restarts Agekube-dns-v11-ey14j 4/4 Running 8 1d
8. View the information for the service defined in the Skydns-svc.yml file.
[[email protected] skydns]# kubectl get svc-l k8s-app=kube-dns--namespace=kube-systemNAME CLUSTER-ip external-IP PORT (S) agekube-dns 10.254. 254.254 <none> /udp,/tcp 1d
9. Test the effect of DNS.
? Deploy a BusyBox pod
[email protected] test]# cat Busybox.yml
apiVersion:v1kind:Podmetadata: name:busybox namespace:defaultspec: containers: - Image:busybox command: sleep "3600 " Imagepullpolicy:ifnotpresent name:busybox restartpolicy:always
Verifying the address resolution of the Kubernetes service, the following shows that DNS parsing is normal.
[email protected] test]# kubectl exec busybox nslookup kubernetesserver: 10.254. 254.254 110.254. 254.254 Name: 1 10.254. 0.1
* Tip: The Kubernetes service is a default service after the Kubernetes cluster is installed.
K8s Introduction Series Extension component (i) DNS installation Chapter