Angular Wont Deploy Docker Desktop + Kubernetes

4/30/2021

I am trying to run an Angular CLI project on my MAC using Docker Desktop and Kubernetes. I have a dockerfile here, which works fine when running the image strictly through docker.

FROM node:14.16.0-alpine3.13 as node
WORKDIR /app
COPY package.json package.json
RUN npm install
COPY . .
RUN npm run build -- --prod

FROM nginx:alpine
VOLUME /var/cache/nginx
COPY --from=node /app/dist/ngDockerApp/* /usr/share/nginx/html/
COPY ./config/nginx.conf /etc/nginx/conf.d/default.conf

The nginx config file is here:

server {
    listen 0.0.0.0:80;
    listen [::]:80;
    default_type application/octet-stream;

    gzip                    on;
    gzip_comp_level         6;
    gzip_vary               on;
    gzip_min_length         1000;
    gzip_proxied            any;
    gzip_types              text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_buffers            16 8k;
    client_max_body_size    256M;

    root /usr/share/nginx/html;

    location / {
        try_files $uri $uri/ /index.html =404;
    }
}

When I run docker run -d -p 8080:80 nginx-angular it spins up the image and runs fine. However, I have a kubernetes deployment I am trying to run via docker desktop, and have no idea what I am doing wrong, and why I cant bring it up.

The deployment file is here:

apiVersion: v1
kind: Service
metadata:
  name: ui-svc
  labels:
    app: ui
spec:
  type: NodePort
  selector:
    app: ui
  ports:
  - port: 80
    targetPort: 80
    nodePort: 31000

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ui
  labels:
    app: ui
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ui
  template:
    metadata:
      labels:
        app: ui 
    spec:
      containers:
        - name : ui
          image: nginx-angular
          imagePullPolicy: Never
          ports:
            - containerPort: 80
          resources:
            limits:
              memory: "500Mi"
              cpu: "90m"

EDIT

## kubectl get all -o wide
NAME                      READY   STATUS    RESTARTS   AGE   IP           NODE             NOMINATED NODE   READINESS GATES
pod/ui-6cc55b59c4-24tv7   1/1     Running   0          7s    10.1.0.124   docker-desktop   <none>           <none>

NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE   SELECTOR
service/kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP        21d   <none>
service/ui-svc       NodePort    10.100.72.12   <none>        80:31000/TCP   8s    app=ui

NAME                 READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES          SELECTOR
deployment.apps/ui   1/1     1            1           8s    ui           nginx-angular   app=ui

NAME                            DESIRED   CURRENT   READY   AGE   CONTAINERS   IMAGES          SELECTOR
replicaset.apps/ui-6cc55b59c4   1         1         1       8s    ui           nginx-angular   app=ui,pod-template-hash=6cc55b59c4


## kubectl get nodes -o wide
NAME             STATUS   ROLES    AGE   VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE         KERNEL-VERSION      CONTAINER-RUNTIME
docker-desktop   Ready    master   21d   v1.19.7   192.168.65.4   <none>        Docker Desktop   4.19.121-linuxkit   docker://20.10.5

Just to clarify, 10.100.72.12:31000 (nodeport) and 192.168.65.4:31000 do not work.

I've tried localhost:80, and I have tried the internal node IP address:80, and nothing shows up. What am I missing?

-- foo_bar_zing
angular
docker
kubernetes
nginx

1 Answer

5/4/2021

Here is what I found out. For local deployments, run kubectl cluster info. This gave me the following:

$ kubectl cluster-info
Kubernetes master is running at https://kubernetes.docker.internal:6443
KubeDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

I then took http://kubernetes.docker.internal:<nodeport> and put that in the browser.I could then see my app.

-- foo_bar_zing
Source: StackOverflow