Helm Charts with Travis CI
When deploying an application, specifically on Kubernetes, it is required to define and manage several Kubernetes resources such as pods, services, deployments, and replicasets. These hooks all live in a YAML based file. Let’s hop in.
What is Helm?
Helm is a package manager for Kubernetes. It allows you to easily configure, add, remove things, and deploy applications and services on Kubernetes clusters.
Usage
Let’s grab Helm from Katakoda:
curl -L https://git.io/get_helm.sh | bash
Let’s build the Helm package:
helm package tomcat
Let’s now define the repo index:
helm repo index .
Let’s add a new repository to the Helm client, it’s a lot like adding a project to a GitHub repository:
helm init
helm repo add (img name) (repo link)
helm repo update
helm install (repo name) --name tomcat
helm status tomcat
helm delete tomcat
Starting with Travis CI
Let’s get a vaild .travis.yml
going:
language: minimal
if: branch = master
before_install:
- curl -L https://git.io/get_helm.sh | bash
- helm init --client-only
script:
- mkdir files-to-gh-pages
- echo $(pwd)
- helm package charts/tomcat-prod -d files-to-gh-pages
- helm package charts/tomcat -d files-to-gh-pages
- cp README.md files-to-gh-pages
- cd files-to-gh-pages
- helm repo index .
- ls -ltr
deploy:
provider: pages
github_token: $GITHUB_TOKEN
local_dir: files-to-gh-pages
target_branch: gh-pages
verbose: true
skip_cleanup: true
keep_history: true
on:
branch: master
As you can see we are going to push this to a gh-pages
, via the hook provider: pages
. Now let’s make a folder in our project entitled charts
then inside of charts
let’s make one called tomcat
. I made a .helmignore
file, and I’ll share it below:
# Negation (prefixed with !). Only one pattern per line.
.DS_Store
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
*.swp
*.bak
*.tmp
*~
.project
.idea/
*.tmproj
.vscode/
In your tomcat
directory let’s make a file called Chart.yaml
:
apiVersion: v1
appVersion: "9.0.26"
description: A Helm chart for Tomcat 9 (with Oracle openjdk13)
name: tomcat
version: 0.1.2
Now we need to make another yaml
file, as I said in. the beginning - Helm’s method of action is getting configuration settings from yaml
files. Let’s call this file values.yaml
:
replicaCount: 3
image:
repository: tomcat
tag: 9.0.26-jdk13-openjdk-oracle
pullPolicy: IfNotPresent
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
service:
type: ClusterIP
port: 8080
targetPort: 8080
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: "tomcat"
# kubernetes.io/tls-acme: "true"
hosts:
- host: (your host)
paths: []
tls: []
resources: {}
nodeSelector: {}
tolerations: []
affinity: {}
Travis will now deploy Helm and in turn, Helm will now use the newly built image to deploy Helm Charts. You can repeat this process say if you had another directory entitled tomcat-prod
, but just redoing the following steps above:
Conclusion
So there you have it, you now know what Helm is all about, and why not give it a shot? See how Travis makes an easier process even easier.
Happy building!
If you have any questions please email me at montana@travis-ci.org.