Kubernetes is a container-based platform for deploying, scaling and running applications. Buddy lets you automate your Kubernetes delivery workflows with a series of dedicated K8s actions.
Each time you make changes to your application code or Kubernetes configuration, you have two options to update your cluster:
kubectl apply or
kubectl set image.
In such case your workflow most often looks like this:
- Edit code or configuration .YML
- Push it to your Git repository
- Build an new Docker image
- Push the Docker image
- Log in to your K8s cluster
kubectl set image
With Buddy you can avoid most of these steps by doing a simple push to Git! :)
Actions used in this guide:
How to automate Kubernetes releases on every push
Buddy is a Continuous Delivery tool that you can use to automate your whole K8s release workflow, including:
- managing configuration changes of a K8s Deployment
- deployments of code changes
- managing Dockerfile updates
- building Docker images and pushing them to the Docker registry
- applying new images on your K8s cluster
If you often use
kubectl apply or
kubectl set image, this is for you!
Configuring delivery pipeline
Add a new pipeline, set the trigger mode to On every push, and select the branch that will trigger the pipeline
Add the Build Docker image action. There you select the Dockerfile path, Docker repository, and the name of the image that you want to push.
Depending on your scenario, add Set K8s Image or Apply K8s Deployment action
You can use the number of the revision for the tag with Buddy parameters.
Scenario 1: If you use kubectl set image go with Set K8s Image action:
Select which container should be replaced and which image you want to use. Make sure to enter the name and tag of the image from step #2 above.
Buddy will turn off the running nodes and switch them back on with the new image version.
If you use a tag which is constant for every execution (eg.
branchName) but different from 'latest', make sure to set the Pull Policy to 'Always'. You can read more about updating images here.
Scenario 2: If you use kubectl apply go with Apply K8s Deployment action:
With every change in the YAML config or in your app code, Buddy will apply the deployment and Kubernetes will start transforming the containers to the desired state.
The action will wait for the status of deployment, checking its rollout status. If any errors occur, the pipeline will stop as 'failed'.
How to automate running Kubernetes pods or jobs
If you often run tasks in a container, such as:
- DB migration during the deployment of new version
- batch jobs, eg. creating a directory structure for a new version of your app
you can either use pods or jobs. The first type launches a single pod with the task; the second one launches a series of pods until a specified number of them ends with a successful status.
Pipeline configuration for running Kubernetes pods or jobs
Let's say you have an application on a K8s cluster and the repository contains as follows:
- source code of your application
- a Dockerfile with instructions on creating an image of your app
- DB migration scripts
- a Dockerfile with instructions on creating an image that will run the migration during the deployment (db migration runner)
In this case, you can configure a pipeline that will:
A. Build application and migration images (first action) B. Push them to the Docker Hub (second action)
C. Trigger the DB migration using the previously built image (third action). You can define the image, commands and deployment using a YAML file:
Once you make a push, the pipeline will automatically build and push the images to the repository and run your migration scripts. How cool is that?
The job action will wait until the command has finished executing. If the exit status is different than 0, the action will be labeled as 'failed'
D. The last action is using either Apply K8s Deployment or Set K8s Image to update the image in your K8s application. Once you add the action, the whole pipeline will look like this:
When everything is in place, make a push once again and watch Buddy automagically perform the whole workflow. Hurray! :)
Hope you enjoyed this guide. If you'd like to see how it all works in practice, go ahead and sign up for a free trial now. If you're not sure if you can apply our solution to your workflow, please reach out on the live-chat or drop a line to firstname.lastname@example.org and we'll do it for you.