<p>I deployed my container in kubernetes pod, andd pod and related services are up and running.</p>

<p>please find the below pod and deployment status of the pods</p>

<pre><code>root@jenkins-linux-vm:/home/admin/kubernetes# kubectl get pods
NAME                                  READY   STATUS    RESTARTS   AGE
angular-deployment-5d5fbf967c-zvzvl   1/1     Running   0          70m

root@jenkins-linux-vm:/home/admin/kubernetes# kubectl get svc
NAME              TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
angular-service   NodePort   10.96.16.68    &lt;none&gt;        80:31000/TCP     79m

root@jenkins-linux-vm:/home/admin/kubernetes# kubectl get deployment
NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
angular-deployment   1/1     1            1           70m

</code></pre>

<p>please find the below curl access</p>

<pre><code>root@jenkins-linux-vm:/home/admin/kubernetes# kubectl exec -it angular-deployment-5d5fbf967c-zvzvl curl 10.0.0.1:31000
curl: (7) Failed to connect to 10.0.0.1 port 31000: Connection refused
command terminated with exit code 7
</code></pre>

<p>Even though i am not able to access my application services in the browser as like below.</p>

<pre><code>https://10.0.0.1:31000
</code></pre>

<pre><code>apiVersion: apps/v1
kind: Deployment 
metadata: 
  name: angular-deployment 
spec: 
  selector: 
    matchLabels: 
      app: frontend-app 
  replicas: 1
  template: 
    metadata: 
      labels: 
        app: frontend-app 
    spec: 
      containers: 
      - name: frontend-app 
        image: ${IMAGE_NAME}:${IMAGE_TAG} 
        ports: 
        - containerPort: 80 
---
kind: Service 
apiVersion: v1 
metadata: 
  name: angular-service 
spec: 
  selector: 
    app: frontend-app 
  ports: 
  - protocol: TCP 
    port: 80 
    targetPort: 80 
    nodePort: 31000 
  type: NodePort
</code></pre>

<pre><code>root@jenkins-linux-vm:/home/admin# kubectl describe pod angular-deployment-556c47f666-9d2x4
Name:         angular-deployment-556c47f666-9d2x4
Namespace:    pre-release
Priority:     0
Node:         poc-worker2/10.0.0.2
Start Time:   Sat, 18 Jan 2020 08:47:35 +0000
Labels:       app=frontend-app
              pod-template-hash=556c47f666
Annotations:  &lt;none&gt;
Status:       Running
IP:           10.32.0.8
IPs:
  IP:           10.32.0.8
Controlled By:  ReplicaSet/angular-deployment-556c47f666
Containers:
  frontend-app:
    Container ID:   docker://43fea22e4c1d49e0c94fc8aca3a4b41df44b5f91f45ea29ede263c5a6bcf6503
    Image:          frontend-app:future-master-fix-f2d2a8bd
    Image ID:       docker://sha256:0099587db89de9ef999a7d1f087d4781e73c491b17e89392e92b08d2f935ad27
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Sat, 18 Jan 2020 08:47:40 +0000
    Ready:          True
    Restart Count:  0
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-r67p7 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-r67p7:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-r67p7
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  &lt;none&gt;
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age   From                       Message
  ----    ------     ----  ----                       -------
  Normal  Scheduled  21s   default-scheduler          Successfully assigned pre-release/angular-deployment-556c47f666-9d2x4 to poc-worker2
  Normal  Pulled     17s   kubelet, poc-worker2  Container image "frontend-app:future-master-fix-f2d2a8bd" already present on machine
  Normal  Created    16s   kubelet, poc-worker2  Created container frontend-app
  Normal  Started    16s   kubelet, poc-worker2  Started container frontend-app

</code></pre>

<p>please find the below are the svc for deployment</p>

<pre><code>root@jenkins-linux-vm:/home/admin# kubectl describe svc angular-service
Name:                     angular-service
Namespace:                pre-release
Labels:                   &lt;none&gt;
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"angular-service","namespace":"pre-release"},"spec":{"ports":[{"no...
Selector:                 app=frontend-app
Type:                     NodePort
IP:                       10.96.227.143
Port:                     &lt;unset&gt;  80/TCP
TargetPort:               80/TCP
NodePort:                 &lt;unset&gt;  31000/TCP
Endpoints:                10.32.0.4:80,10.32.0.8:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;

</code></pre>

<p>Please find the docker file here</p>

<pre><code>FROM node:12.2.0

# set working directory
WORKDIR /app

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

# install and cache app dependencies
COPY package.json /app/package.json

# add app
COPY . /app

# start app
CMD ng serve --host 0.0.0.0
</code></pre>

<p>Can you please some one help me how to fix this issue</p>

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

<p>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. </p>

<p>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 <code>serving</code> the index.html page it's the end product after you build your <code>Angular</code> or <code>React</code> applications.</p>

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

<pre><code>#Stage0: builder, based on Node alpine imagine to build and compile your angular code
FROM 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 work
RUN npm install 

COPY . . 

# This is normal build, it does ng build
RUN npm run build

#Stage 1, based on Nginx imagine, to have only the compile app inside nginx folders to serve
FROM nginx:1.15

COPY --from=builder /app/dist/ /usr/share/nginx/html

# This one copies the local nginx.conf file as default.conf for nginx to let it serve
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
</code></pre>

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

<pre><code>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 *;
    }
  }
}
</code></pre>

<p>Make sure you run <code>docker run</code> on local machine before you deploy it on to cluster. </p>

<p>Hope this helps.</p>
