Nslookup failure

I was going through another challenge on killercoda but even after the right steps, verification fails. Can someone confirm if I did the right steps?

controlplane $ kubectl run nginx-pod-cka --image=nginx --dry-run=client -o yaml > nginx-pod-cka.yaml
controlplane $ vi nginx-pod-cka.yaml 
controlplane $ cat nginx-pod-cka.yaml 
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx-pod-cka
  name: nginx-pod-cka
spec:
  containers:
  - image: nginx
    name: nginx-pod-cka
    ports:
    - containerPort: 80
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}
controlplane $ kubectl create -f nginx-pod-cka.yaml 
pod/nginx-pod-cka created
controlplane $ kubectl expose pod nginx-pod-cka --port 80 --target-port 80 --name nginx-service-cka --dry-run=client -o yaml > nginx-service-cka.yaml
controlplane $ vi nginx-service-cka.yaml 
controlplane $ cat nginx-service-cka.yaml 
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    run: nginx-pod-cka
  name: nginx-service-cka
spec:
  type: ClusterIP
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: nginx-pod-cka
status:
  loadBalancer: {}
controlplane $ kubectl apply -f nginx-service-cka.yaml 
service/nginx-service-cka created
controlplane $ kubectl get po,svc
NAME                READY   STATUS    RESTARTS   AGE
pod/nginx-pod-cka   1/1     Running   0          81s


NAME                        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
service/kubernetes          ClusterIP   10.96.0.1       <none>        443/TCP   19d
service/nginx-service-cka   ClusterIP   10.99.222.177   <none>        80/TCP    4s
controlplane $ cp nginx-pod-cka.yaml busybox.yaml
controlplane $ vi busybox.yaml 
controlplane $ cat busybox.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: busybox
spec:
  containers:
  - image: busybox:1.28
    name: nginx-pod-cka
    command: ["sleep", "3600"]
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}
controlplane $ kubectl apply -f busybox.yaml 
pod/busybox created
controlplane $ kubectl get po,svc
NAME                READY   STATUS    RESTARTS   AGE
pod/busybox         1/1     Running   0          9s
pod/nginx-pod-cka   1/1     Running   0          2m26s


NAME                        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
service/kubernetes          ClusterIP   10.96.0.1       <none>        443/TCP   19d
service/nginx-service-cka   ClusterIP   10.99.222.177   <none>        80/TCP    69s
controlplane $ kubectl exec busybox -- nslookup nginx-service-cka 
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local


Name:      nginx-service-cka
Address 1: 10.99.222.177 nginx-service-cka.default.svc.cluster.local
controlplane $ kubectl exec busybox -- nslookup nginx-service-cka  > nginx-service.txt
controlplane $ cat nginx-service.txt 
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local


Name:      nginx-service-cka
Address 1: 10.99.222.177 nginx-service-cka.default.svc.cluster.local
controlplane $
````Preformatted text`

Hi @piyushgaur2011

I am not sure how the validation with Killer works. You might get an answer if you raise this in their Slack.

I just wanted to verify if the steps I did are correct.

As you are able to lookup the nginx Service from within the busybox Pod, this looks correct.

1 Like

alright, thanks a ton.

1 Like

This is absolutely correct for service nslookup.
For nslookup for pod:

~ kubectl get pods -o wide

Take the IP the pod for which you want to lookup.

~ kubectl exec busybox -- nslookup 172-17-0-3.default.pod.cluster.local

Store the output

~ kubectl exec busybox -- nslookup 172-17-0-3.default.pod.cluster.local > nginx-pod.txt

This is sorted now. Thanks a ton.

HI piyushgaur2011,
how did you solve this question.

I solved it as mentioned above. It was an issue with the scenario.

Hi @piyushgaur2011 @piyush1687 and @Santosh_KodeKloud , I had just tried the exact scenario, I thought my process was correct. I also double-checked with the manifests and outputs posted in the thread. My nslookup works for pod as well as service. but verification is still wrong. I apologise but I do not see in the thread where the solution was posted. I assumed the question was mentioning service instead of pod, but I still wasn’t able to resolve.

Please help.