Automating Deployment (for CICD)

Automating Deployment (for CICD)

Spring Application Deployed with Kubernetes

Step by step building an application using Spring Boot and deployed via Docker on Kubernetes with Helm

full course
  1. Setup: IDE and New Project
  2. Create the Data Repository
  3. Building a Service Layer
  4. Create a REST Controller
  5. Logging, Tracing and Error Handling
  6. Documentation and Code Coverage
  7. Database as a Service
  8. Containerize the Service With Docker
  9. Docker Registry
  10. Automated Build Pipeline
  11. Helm for Deployment
  12. Setting up a Kubernetes Cluster
  13. Automating Deployment (for CICD)
  14. System Design
  15. Messaging and Event Driven Design
  16. Web UI with React
  17. Containerizing our UI
  18. UI Build Pipeline
  19. Put the UI in to Helm
  20. Creating an Ingress in Kubernetes
  21. Simplify Deployment
  22. Conclusion and Review

Now that we’ve deployed our application, lets reduce some of the manual steps and make our deployments more reproducible with the intent of eventually making them automated for CI/CD.

Publish our Chart to the Chart Repository

Normally, we would need to create a helm chart repository, however, codefresh has given us one by default. We just need to make it available to our pipeline and add some steps to push a chart up.

Go to our pipeline workflow for medium-customer. On the right side you should see some tabs as well as a gear. Click on the gear. Click on Import from Shared Configuration and choose CF_HELM_DEFAULT (which is the default helm repository codefresh gives us). We don’t need to do anything else here so close up the environment variables window.

Back on the workflow we need to add some new steps:

    title: Update Helm Chart Version
    stage: helmpublish
    image: gksoftware/yq
    working_directory: '/codefresh/volume/medium-customer'
      - CHART=src/main/helm/medium-customer
      - yq w -i ${CHART}/values.yaml image.tag '"${{CF_SHORT_REVISION}}"'
      title: Push Helm Chart to Chart Repository
      stage: helmpublish
      image: codefresh/cfstep-helm
      working_directory: '/codefresh/volume/medium-customer'
        - CHART_REF=src/main/helm/medium-customer/
        - ACTION=push

Again, this is yaml so be very careful about formatting. What we’re doing here is opening up the values.yaml for the chart, updating the tag version to the tag that we just used for the docker image and then using codefresh’s custom step to package up the chart, update the chart index and publish the updated index.

What we’re doing with a chart and chart repository is essentially creating a ‘package’ of our application which helm can use to install the app. This is very similar to the package managers that we used to install kubectl. However, in this case we’re going to use helm to tell kubernetes to install and start up our application.

Make sure that you run this pipeline now. We need to publish the chart with the new pipeline steps to make it available in the next section.

Testing it Out

Lets try it out with minikube. First destroy our running application

helm delete medium

Now lets configure helm to be able to talk to codefresh’s helm chart repository. First we need access, so we’ll create an API token. Go to User Accounts in the lower left of the console screen. Click on generate in the API Keys section. Create a key called helmaccess click the SCOPES checkbox to give all access. Click CREATE and then use the eyeball in the API KEY section to view the generated token. Save this somewhere locally, since we’ll never be able to view it again.

At this point I had to switch over my command line to Git Bash (since I’m on windows) if you’re on windows, you may want to do the same.

First install the chartmuseum plugin that will let us talk to codefresh’s chart repository.

helm plugin install

Next add your access token to the environment

export HELM_REPO_ACCES_TOKEN="<your access token>"

now link the codefresh chart repo to your helm

helm repo add codefresh cm://<your account name>/default

update your view

helm repo update

now use helm to install the chart

helm install medium codefresh/medium-customer

As you can see here we’re using the chart repository to reference the chart instead of the local path.

The advantage of a chart is that now I don’t need to know any thing about the source code in order to deploy my application. As long as I can access this chart repository (and the container image registry) I can deploy this service to ANY kubernetes cluster I can spin up.

0 comments on “Automating Deployment (for CICD)Add yours →

Leave a Reply

Your email address will not be published. Required fields are marked *