How to Debug Kubernetes App Errors Like a Pro 2/3

JJotah
4 min readMay 1, 2023

--

Continuing with our debugging journey, let’s move on to create deployment definition

kubectl create deploy nginx --image=nginx --dry-run=client -o yaml > deploy-nginx-course.yaml -- sleep 23132

Using the “kubectl run” command with the “ — dry-run” option, we can preview and export the yaml definition to a file. In addition, to avoid forgetting how to launch a command in kubernetes, I sent a command as a parameter, which gave me the definition to copy and paste in the container. Afterwards, we can open the exported yaml file and add the sidecar to it. The sidecar can include a “sleep” command to allow the container to run.

We open the file “deploy-nginx-course.yaml” and we will add it the sidecar

vi deploy-nginx-course.yaml

In this process, we added a sidecar container with Ubuntu and a command to pause the container. After editing the YAML file and saving it, we applied it to Kubernetes to ensure that the deployment and pods were created successfully.

kubectl apply -f deploy-nginx-course.yaml
kubectl get deploy && kubectl get pod

Once the pod is deployed, we check the status of the containers in the pod. If the application is not ready, we check the logs again. However, if the application is ready and did not restart, we can go into the Ubuntu container.

kubectl exec -it POD-NAME -c CONTAINER-NAME COMMAND

Typically, I use the Alpine or Ubuntu image as it comes with shell commands like “sh” and “bash”. This helps us access the container without needing to check any Entrypoints for other images. After accessing the Ubuntu container, we install the curl command to check if the Nginx is running correctly.

apt update
apt install curl netcat -y
curl localhost
nc -v localhost 80

If the application seems to be working fine, we need to ensure that the problem is not within the container itself. We can check this by testing if the Nginx is available outside the pod. To do this, we create a new container in the same namespace as the application.

kubectl run alpine --image=alpine -- sleep 231312

We then create an Alpine pod and remove the sidecar from the container. Next, we copy the Nginx pod IP and install the curl command to test it.

kubectl get pod -o wide
kubectl exec -it alpine sh
apk add curl
curl POD-IP

We also test it using the DNS name with “pod-ip-address.my-namespace.pod.cluster-domain.example.”

I also recommend you to launch the same test with the same pod in different namespace where your application is located. If something failed you need to check the following solutions

We also recommend launching the same test with the same pod in a different namespace where the application is located. If something fails, we need to check the following points:

  1. Check the port exposed by deployment
  2. Check the port exposed by the container/pod
  3. Check any network policy created on your namespace
  4. Check any security policy or something that could make it blocked.

After ensuring that the application is working fine, we move on to checking the service and ingress connection.

In the next part, we will continue learning how to debug like a pro. Stay tuned and don’t miss it! Follow the link to the next page, see you!

--

--

JJotah

Cloud Architect | Blogger | Kubernetes Enthusiast | CKS | CKA | CKAD | Terraform | Golang | LinkedIn: Juan José Ruiz | GitHub: JJotah