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

1/8/2018

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:

# 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

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.

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.

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.

-- ALYS
angular
docker
kubernetes
minikube

3 Answers

1/8/2018

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

-- Lev Kuznetsov
Source: StackOverflow

1/8/2018

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.

Try to use:

ng serve --host 0.0.0.0
-- Sebastian
Source: StackOverflow

6/29/2018

Try exposing port 80 instead of 4200 i.e.

kubectl run frontend --image=frontend:v1 --port=80
-- user10010139
Source: StackOverflow