Unable to serve Angular application through minikube (Kubenetes) on Windows


Unable to serve Angular application through minikube (Kubenetes) on Windows



I am running Docker for Windows and Minikube (Kubernetes) to serve an Angular application. The angular application is served using ng serve and is working properly on windows. I created the below Dockerfile:


ng serve


# Use an official Nodejs runtime as a parent image
FROM node:6.10.3

#Create an unprivileged user 'app'
#Install dependencies
RUN useradd --user-group --create-home --shell /bin/false app &&
npm install -g grunt-cli &&
npm install -g @angular/cli

# Define environment variable
ENV ENVIRONMENT="dev" HOME=/home/app

#Copy the code to the image
COPY . $HOME/frontend/

#Chmod the files to allow unprivileged user 'app' to read/write
RUN chown -R app:app $HOME/*

#Use unprivileged user 'app' to run the app inside the container
USER app

#Set Current Working Directory of the runtime
WORKDIR $HOME/frontend

#Install NPM dependencies
RUN npm install

# Make port 8080 and 4200 available to the world outside this container
EXPOSE 4200

# Start the webpack server when the container launches
CMD ng serve



I have my environment variables set in windows for minikube along with my Docker variables (minikube docker-env)


DOCKER_API_VERSION
DOCKER_CERT_PATH
DOCKER_HOST
DOCKER_MACHINE_NAME
DOCKER_TLS_VERIFY



I built the Docker image and tagged it as v1 :


docker build -t frontend:v1 .



I deployed the POD from the image and exposed the deployment:


kubectl run frontend --image=frontend:v1 --port=4200
kubectl expose deployment frontend --type=LoadBalancer



The kubectl get pods is showing my pod as running and kubectl get deployments is showing that my deployment is available


kubectl get pods


kubectl get deployments



I executed a curl using kubectl exec curl localhost:4200, which executes on the container, and it is properly returning my page but when I try to run my service using minikube service frontend it opens the browser but can't reach my application.


kubectl exec curl localhost:4200


minikube service frontend



It is worth noting that I did the same exact steps with a normal Nodejs application running using node server.js and it is served correctly using the same exact steps.


node server.js



Any idea why my angular application is not served over Kubernetes when started using ng serve or how to go about figuring out what is the issue? I can see the mappings are correct from the Kubernetes Dashboard.




3 Answers
3



This is probably more related to angular-cli. ng serve only binds to localhost by default. Therefore your docker container is not listening on it's public IP address.


ng serve


localhost



Try to use:


ng serve --host 0.0.0.0





I can't thank you enough! That was it.
– ALYS
Jan 9 at 14:59



Minikube doesn't really support service type of LoadBalancer. It won't puke on it, but you should read up on what that really means. Do


minikube service list



to see an actual endpoint you can hit. The point from Sebastian may still apply





Seems to work fine. github.com/kubernetes/minikube/issues/384 - "LoadBalancer services run fine on minikube, just with no real external load balancer created. LoadBalancer services get a node port assigned too so you can access services via minikube service <name> to open browser or add --url flag to output service URL to terminal."
– ALYS
Jan 9 at 15:02






Exactly. You ask for a load balancer but none is created
– Lev Kuznetsov
Jan 9 at 16:02



Try exposing port 80 instead of 4200 i.e.


80


4200


kubectl run frontend --image=frontend:v1 --port=80






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift