How it works...

We have set up several components to see how DNS entries are created initially. The Kubernetes Service name is especially important for determining the name of a DNS.

However, Kubernetes Service has 2 modes, either normal service or headless service. Normal service has already been described in the preceding section; it has its own IP address. On the other hand, headless service doesn't have an IP address.

Let's see how to create a headless service and how name resolution works:

  1. Create a headless service (specify --cluster-ip=None) for apache on chap8-domain1 and chap8-domain2:
$ kubectl expose deploy my-apache --namespace=chap8-domain1 --name=my-apache-svc-hl --port=80 --type=ClusterIP --cluster-ip=None
service "my-apache-svc-hl" exposed

$ kubectl expose deploy my-apache --namespace=chap8-domain2 --name=my-apache-svc-hl --port=80 --type=ClusterIP --cluster-ip=None
service "my-apache-svc-hl" exposed
  1. Check there is no IP address for those two headless services with the following command:
$ kubectl get svc my-apache-svc-hl --namespace=chap8-domain1
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-apache-svc-hl ClusterIP None <none> 80/TCP 13m


$ kubectl get svc my-apache-svc-hl --namespace=chap8-domain2
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-apache-svc-hl ClusterIP None <none> 80/TCP 13m
  1. Launch the busybox pod in the foreground:
$ kubectl run -it busybox --restart=Never --image=busybox
  1. In the busybox pod, query those two services. It must show the addresses as the pod's address (172.168.0.4 and 172.168.0.5):
# nslookup my-apache-svc-hl.chap8-domain1.svc.cluster.local
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: my-apache-svc-hl.chap8-domain1.svc.cluster.local
Address 1: 172.17.0.4


# nslookup my-apache-svc-hl.chap8-domain2.svc.cluster.local
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: my-apache-svc-hl.chap8-domain2.svc.cluster.local
Address 1: 172.17.0.5
  1. Exit the busybox pod and delete it:
# exit
$ kubectl delete pod busybox
pod "busybox" deleted
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.198