Guys, I’m stuck with Mock Exam question 7. Create an Nginx pod called Nginx-reso . . .

Alexander Nabokikh:
Guys,
I’m stuck with Mock Exam question 7. Create an Nginx pod called Nginx-resolver using image Nginx, expose it internally with a service called nginx-resolver-service. Test that you can look up the service and pod names from within the cluster. Use the image: busybox:1.28 for DNS lookup.)
I can resolve service and pod when I do nslookup from within the pod but cannot redirect output to the file. Can you help me to figure this out?

controlplane $ k run test-resolver --image=busybox:1.28 --rm -it -- nslookup nginx-resolver-service.default.svc.cluster.local
pod "test-resolver" deleted
error: timed out waiting for the condition

Deekshith Hadil:
It’s timing out. Likely the service is not created properly.
I prefer creating a testpod separately and then run exec inside that testpod to test. Because the above command has to go through couple of steps and then remove pod or change status to completed at the end.

my way.

  1. k run test-resolver --image=busybox:1.28 --command – sleep 5000
  2. k exec -it test-resolver – sh
  3. then run ns lookup or whatevetr you want inside the pod.
    This way if there is problem with service, have a look, fix and get back inside pod to run command again.

Alexander Nabokikh:
It works the way you described. The problem however that I wan’t to redirect nslookup to the file as it stands in the question.

Deekshith Hadil:

  1. What do you get when you run k exec -it test-resolver -- nslookup nginx-resolver-service.default.svc.cluster.local ?

Deekshith Hadil:
If you get output, add > /path/to/file.txt

Alexander Nabokikh:
pod "test-resolver" deleted
error: timed out waiting for the condition
If I open a shell on the running container though I get:
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: nginx-resolver-service
Address 1: 10.96.61.11 nginx-resolver-service.default.svc.cluster.local

Alexander Nabokikh:
so the service is ok

Deekshith Hadil:
k exec -it test-resolver -- nslookup nginx-resolver- service.default.svc.cluster.local > /to/file.txt

Deekshith Hadil:

controlplane $ k run test-resolver --image=busybox:1.28 --rm -it -- nslookup nginx-resolver-service.default.svc.cluster.local
pod "test-resolver" deleted
error: timed out waiting for the condition

This could be failing because of some other reason. Do describe the pod or check logs of the pod.

Md Ishaq R:
k run test-resolver --image=busybox:1.28 --rm -it – nslookup nginx-resolver-service --restart=Never

Md Ishaq R:
try this command

Spa Mki Maki:
I had the same error. I did following:

k run test-nslookup --image=busybox --rm -it -- sh | tee output.filename

Spa Mki Maki:
tee helps you interact with the console but it records the output in the file