Last exam
Set configuration context $ kubectl config use-context k8s;
Create a deployment as follows;
Name: nginx-dns;
Exposed via a service: nginx-dns;
Ensure that the service & pod are accessible via their respective DNS records;
The container(s) within any pod(s) running as a part of this deployment should use the nginx image;
Next,use the utiliity nslookup to look up the DNS records of the service & pod and write the output to /opt/service.dns and /opt/pod.dns respectively;
Ensure you use the busybox:1.28 image (or earliser) for any testing, an the latest release has an unpstream bug which impacts the use of nslookup;
Analysis topic
First set Context: kubectl config use-context k8s;
Create deployment under the following conditions:
Name: nginx-dns;
exposed service: nginx-dns;
ensure access to the Service and Pod via respective DNS records;
any Pod running containers should use nginx mirror;
Next, nslookup DNS record lookup service and the pod, and the output is written /opt/service.dns and /opt/pod.dns;
ensure busybox: 1.28 mirroring (or earlier) test, the latest version has unpstream wrong, it will affect the use of nslookup;
answer
Create a deployment of named nginx-dns, and a service, port 80
kubectl run nginx-dns --expose=true --port=80 --image=nginx
Use: kubectl get pods - o wide
get the pod IP: 192.168.155.100
Start a run nslookup of busybox pod:
kubectl run busybox -it --rm --generator=run-pod/v1 --image=busybox:1.28 sh
carried out:
nslookup nginx-dns
with
nslookup 192.168.155.100
The end result service
is dns
saved /opt/service.dns
; pod
the dns
saved/opt/pod.dns
/ # mkdir opt
/ # nslookup nginx-dns > /opt/service.dns
/ # cat /opt/service.dns
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: nginx-dns
Address 1: 10.99.28.72 nginx-dns.default.svc.cluster.local
/ # nslookup 192.168.155.100 > /opt/pod.dns
/ # cat /opt/pod.dns
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local
Name: 192.168.155.100
Address 1: 192.168.155.100 192-168-155-100.nginx-dns.default.svc.cluster.local
/ #
Resolve
Official website DNS Pod and analytical documentation Service:
https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/
Service A record
-Service (except headless Service) will be assigned a DNS A record format my-svc.my-namespace.svc.cluster-domain.example
. The DNS record to resolve the ClusterIP Service.
Headless Service (ClusterIP as None) will be assigned a DNS A record format my-svc.my-namespace.svc.cluster-domain.example
. The DNS record set to resolve the IP address of the selected set of Service of Pod.
Service SRV records
-Service (including headless Service) nomenclature ports (port name) is assigned a SRV record, the format _my-port-name._my-port-protocol.my-svc.my-namespace.svc.cluster- domain.example:
For a general-Service (non headless Service), the SRV record to resolve the domain name and its port number my-svc.my-namespace.svc.cluster-domain.example
For a Headless Service, the SRV record to resolve multiple results: the results are to be each of a rear end of the Pod Service, including the port number and its name Pod auto-generated-pod-name.my-svc.my-namespace .svc.cluster-domain.example
Pod A record
Pod will {podIIP}.my-namespace.pod.cluster.local
be assigned a DNS A record of this form.
For example, Namespace default name with DNS cluster.local
, the IP address is a Namespace in 1.2.3.4
the Pod will have an entry: 1-2-3-4.default.pod.cluster.local
.