100-Days-Of-DevOps-Challenge-KodeKloud

Fix Python App Deployed on Kubernetes Cluster

One of the DevOps engineers was trying to deploy a python app on Kubernetes cluster. Unfortunately, due to some mis-configuration, the application is not coming up. Please take a look into it and fix the issues. Application should be accessible on the specified nodePort.

Note: The kubectl on jump_host has been configured to work with the kubernetes cluster.

Steps

  1. Let’s see the pod status

     kubectl get pods
     kubectl describe pod pod-name
    

    In my case the eorror is look like this:

     Events:
     Type     Reason     Age                    From               Message
     ----     ------     ----                   ----               -------
     Normal   Scheduled  37m                    default-scheduler  Successfully assigned default/python-deployment-devops-678b746b7-f25jg to kodekloud-control-plane
     Normal   Pulling    36m (x4 over 37m)      kubelet            Pulling image "poroko/flask-app-demo"
     Warning  Failed     36m (x4 over 37m)      kubelet            Failed to pull image "poroko/flask-app-demo": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/poroko/flask-app-demo:latest": failed to resolve reference "docker.io/poroko/flask-app-demo:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
     Warning  Failed     36m (x4 over 37m)      kubelet            Error: ErrImagePull
     Warning  Failed     36m (x6 over 37m)      kubelet            Error: ImagePullBackOff
     Normal   BackOff    2m45s (x152 over 37m)  kubelet            Back-off pulling
    

    docker.io/poroko/flask-app-demo:latest the dpeloyment using wrong docker image

  2. Let’s create a k3s-deployment.yaml file from existing deployment

     kubectl get deployments.apps python-deployment-devops -o yaml > k3s-deployment.yaml
    
  3. Let’s fix the docker image

     vi k3s-deployment.yaml
    

    replace docker image in container section with accurate image

  4. Recreate the deployment

     kubectl delete deployments.apps python-deployment-devops
     kubectl apply -f k3s-deployment.yaml
    

    wait for 1-2 minutes and check status

     kubectl get pods
    

    try to access app, but its not working.

  5. Now let’s check the service status

     kubectl get svc
    
      kubectl get svc
     NAME                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
     kubernetes              ClusterIP   10.96.0.1       <none>        443/TCP          23m
     python-service-devops   NodePort    10.96.109.187   <none>        8080:32345/TCP   12m
    

    So service is already running but it’s mapped with wrong target port. let’s fix that

  6. Fixing service

     kubectl get svc python-service-devops -o yaml > k3s-service.yaml
    

    let’s change the target port in k3s-service.yaml file

     vi k3s-service.yaml
    

    configure service

     kubectl apply -f k3s.-svc.yaml
    
  7. Verify results

     kubectl get svc
    

Good to Know?

Application Debugging

Common Misconfigurations

Debugging Workflow

Service Troubleshooting