Spring Application Deployed with Kubernetes
Step by step building an application using Spring Boot and deployed via Docker on Kubernetes with Helm
full course- Setup: IDE and New Project
- Create the Data Repository
- Building a Service Layer
- Create a REST Controller
- Logging, Tracing and Error Handling
- Documentation and Code Coverage
- Database as a Service
- Containerize the Service With Docker
- Docker Registry
- Automated Build Pipeline
- Helm for Deployment
- Setting up a Kubernetes Cluster
- Automating Deployment (for CICD)
- System Design
- Messaging and Event Driven Design
- Web UI with React
- Containerizing our UI
- UI Build Pipeline
- Put the UI in to Helm
- Creating an Ingress in Kubernetes
- Simplify Deployment
- 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:
UpdateChartImageVersion:
title: Update Helm Chart Version
stage: helmpublish
image: gksoftware/yq
working_directory: '/codefresh/volume/medium-customer'
environment:
- CHART=src/main/helm/medium-customer
commands:
- yq w -i ${CHART}/values.yaml image.tag '"${{CF_SHORT_REVISION}}"'
HelmChartPush:
title: Push Helm Chart to Chart Repository
stage: helmpublish
image: codefresh/cfstep-helm
working_directory: '/codefresh/volume/medium-customer'
environment:
- 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 https://github.com/chartmuseum/helm-push.git
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://h.cfcr.io/<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 →