Complete the code to define a Kubernetes Service that uses DNS for service discovery.
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: [1]port and targetPort.The targetPort should match the port on the pods that the service routes to. Here, port 80 is used for simplicity.
Complete the command to get the DNS name of a service in the default namespace.
kubectl get svc [1] -o jsonpath='{.spec.clusterIP}'
The command fetches the Cluster IP of the service named my-service, which is used for DNS-based service discovery.
Fix the error in the DNS query command to resolve the service name inside a pod.
nslookup [1].default.svc.cluster.localThe DNS name for a service includes the service name, namespace, and cluster domain. Here, my-service is the correct service name to query.
Fill both blanks to create a headless service for DNS-based service discovery.
apiVersion: v1 kind: Service metadata: name: headless-service spec: clusterIP: [1] selector: app: my-app ports: - port: 80 targetPort: [2]
Setting clusterIP to null creates a headless service, which allows direct DNS queries to pods. The targetPort should match the pod's port, here 8080.
Fill all three blanks to create a DNS SRV record query for a service in Kubernetes.
dig +short SRV _[1]._tcp.[2].svc.[3]
The SRV record query format is _service._protocol.namespace.svc.cluster-domain. Here, http is the service protocol, default is the namespace, and cluster.local is the default cluster domain.