Kubernetes pod Troubleshoot Kubernetes pod Troubleshoot kubernetes kubernetes

Kubernetes pod Troubleshoot


Here I could see the issue is with your Angular Dockerfile, you are using ng serve if you see your dependencies in package.json you will see "@angular/cli": "*" in order to have that inside your docker you need to add RUN npm install this will install all your dependencies inside your docker container, and you can do ng serve but ng serve is for development locally, it's not a good approach I would say.

To identify these kind of issues, it's advisable to run something like this on local machine in order to find if your docker container is working fine or not, before you could deploy it onto to k8s cluster, as you know kubernetes is a very big universe it will take time to identify the actual problem.

Ok coming to the issue (I can simply add a single command to your dockerfile and add my answer, but I wouldn't suggest that approach. So adding the complete answer which would look good), when you are deploying some frontend related application your docker image need to have the capabilities of serving the index.html page it's the end product after you build your Angular or React applications.

There are several ways this could be done. And there are several tutorials explaining the same, here is something I would suggest, your dockerfile should look like this. Adding comments what they do.

#Stage0: builder, based on Node alpine imagine to build and compile your angular codeFROM node:10-alpine as builder WORKDIR /app COPY package*.json /app/# This is one thing you forgot in your dockerfile, if you add this it might workRUN npm install COPY . . # This is normal build, it does ng buildRUN npm run build#Stage 1, based on Nginx imagine, to have only the compile app inside nginx folders to serveFROM nginx:1.15COPY --from=builder /app/dist/ /usr/share/nginx/html# This one copies the local nginx.conf file as default.conf for nginx to let it serveCOPY ./nginx.conf /etc/nginx/conf.d/default.conf

Please make sure you have nginx.conf file inside your code, file level is same as package.json

server {  listen 80;  sendfile on;  default_type application/octet-stream;  gzip on;  gzip_http_version 1.1;  gzip_disable      "MSIE [1-6]\.";  gzip_min_length   1100;  gzip_vary         on;  gzip_proxied      expired no-cache no-store private auth;  gzip_types        text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;  gzip_comp_level   9;  root /usr/share/nginx/html;  location / {     #try_files $uri $uri/ /index.html =404;    expires -1d;    alias /usr/share/nginx/html/;    try_files $uri$args $uri$args/ /index.html =404;    location ~* \.(?:ico|css|js|gif|jpe?g|png|svg|woff|woff2|ttf|eot)$ {            add_header Access-Control-Allow-Origin *;    }  }}

Make sure you run docker run on local machine before you deploy it on to cluster.

Hope this helps.


If you are accessing the pod via nodeip:nodeport which will only work if you are accessing the pod from outside the cluster using a browser.

Here is a guide on how to expose an application via NodePort. In this case the nodes of your kubernetes cluster need to be accessible i.e should have public ip.

You should be using the cluster ip to access the pod from within the cluster i.e via exec from another pod as shown in below command.

kubectl exec -it angular-deployment-5d5fbf967c-zvzvl curl 10.96.16.68:80

I have a feeling that your docker container is not listening on port 80.