Deployment of and Angular app to a Kubernetes cluster from gitlab using the Auto Dev Ops pipeline failing

7/20/2019

I have a simple angular application, I'm trying to set up the CICD using the Gitlab Auto Dev Ops pipeline, which will deploy to a Kubernetes cluster in Google Cloud. The problem is that the deployment phase is failing.

I have tried what is suggested in this post https://mherman.org/blog/dockerizing-an-angular-app/

This is my Dockerfile

#############
### build ###
#############

# base image
FROM node:12.4.0 as build

# install chrome for protractor tests
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update && apt-get install -yq google-chrome-stable

# 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
RUN npm install
RUN npm install -g @angular/cli@8.1.2

# add app
COPY . /app

# run tests
# RUN ng test --watch=false
# RUN ng e2e --port 4202

# generate build
RUN ng build --output-path=dist

############
### prod ###
############

# base image
FROM nginx:1.16.0-alpine

# copy artifact build from the 'build environment'
COPY --from=build /app/dist /usr/share/nginx/html

# expose port 80
EXPOSE 80

# run nginx
CMD ["nginx", "-g", "daemon off;"]

this is my .gitlab.yml

image: alpine:latest

variables:
  # KUBE_INGRESS_BASE_DOMAIN is the application deployment domain and should be set as a variable at the group or project level.
  # KUBE_INGRESS_BASE_DOMAIN: domain.example.com
  TEST_DISABLED: "true"
  CODE_QUALITY_DISABLED: "true"
  POSTGRES_ENABLED: "false"
  # POSTGRES_USER: user
  # POSTGRES_PASSWORD: testing-password
  # POSTGRES_ENABLED: "true"
  # POSTGRES_DB: $CI_ENVIRONMENT_SLUG
  # POSTGRES_VERSION: 9.6.2

  KUBERNETES_VERSION: 1.11.10
  HELM_VERSION: 2.14.0

  DOCKER_DRIVER: overlay2

  ROLLOUT_RESOURCE_TYPE: deployment

stages:
  - build
  - test
  - deploy  # dummy stage to follow the template guidelines
  - review
  - dast
  - staging
  - canary
  - production
  - incremental rollout 10%
  - incremental rollout 25%
  - incremental rollout 50%
  - incremental rollout 100%
  - performance
  - cleanup

include:
  - template: Jobs/Build.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml
  - template: Jobs/Test.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Jobs/Test.gitlab-ci.yml
  - template: Jobs/Code-Quality.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml
  - template: Jobs/Deploy.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml
  - template: Jobs/Browser-Performance-Testing.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Jobs/Browser-Performance-Testing.gitlab-ci.yml
  - template: Security/DAST.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Security/DAST.gitlab-ci.yml
  - template: Security/Container-Scanning.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml
  - template: Security/Dependency-Scanning.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml
  - template: Security/License-Management.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Security/License-Management.gitlab-ci.yml
  - template: Security/SAST.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml

# Override DAST job to exclude master branch
dast:
  except:
    refs:
      - master

these are the logs I get in gitlab

$ deploy
secret "production-secret" deleted
secret/production-secret replaced
Deploying new release...
Release "production" has been upgraded.
LAST DEPLOYED: Sat Jul 20 22:24:38 2019
NAMESPACE: web-ui-13409730
STATUS: DEPLOYED

RESOURCES:
==> v1/Pod(related)
NAME                         READY  STATUS             RESTARTS  AGE
production-559fb8c7f8-d5j7f  0/1    ContainerCreating  0         3s
production-7cccb8f489-np2v7  0/1    Terminating        24        76m

==> v1/Service
NAME                    TYPE       CLUSTER-IP     EXTERNAL-IP  PORT(S)   AGE
production-auto-deploy  ClusterIP  10.51.249.243  <none>       5000/TCP  99m

==> v1beta1/Deployment
NAME        READY  UP-TO-DATE  AVAILABLE  AGE
production  0/1    1           0          99m

==> v1beta1/Ingress
NAME                    HOSTS                                                                      ADDRESS  PORTS  AGE
production-auto-deploy  xxxxxx.nip.io,xxxxxx.nip.io  80, 443  99m


NOTES:
Application should be accessible at: http://xxxxx.nip.io
Waiting for deployment "production" rollout to finish: 0 of 1 updated replicas are available...

when I look at my nodes in google cloud I can see this

production-559fb8c7f8-d5j7f
CrashLoopBackOff 0 CPU 0 B 0 B web-ui-13409730 17 Jul 20, 2019, 11:24:39 PM

I'm expecting to see the pipeline to success and the application to be available at the given url http://xxxxx.nip.io but instead the deployment stage does not finish.

-- sergio.nava
angular
docker
gitlab
gitlab-ci
kubernetes

0 Answers