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.
python-deployment-devops, its using poroko/flask-demo-appimage. The deployment and service of this app is already deployed.32345 and targetPort should be python flask app’s default port.Note: The kubectl on jump_host has been configured to work with the kubernetes cluster.
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:latestthe dpeloyment using wrong docker image
Let’s create a k3s-deployment.yaml file from existing deployment
kubectl get deployments.apps python-deployment-devops -o yaml > k3s-deployment.yaml
Let’s fix the docker image
vi k3s-deployment.yaml
replace docker image in container section with accurate image
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.
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
Fixing service
kubectl get svc python-service-devops -o yaml > k3s-service.yaml
let’s change the target port in
k3s-service.yamlfile
vi k3s-service.yaml
configure service
kubectl apply -f k3s.-svc.yaml
Verify results
kubectl get svc
kubectl get endpoints shows service targetskubectl port-forward for direct access