Automating the deployment process from Bitbucket Pipelines to Kubernetes involves setting up a continuous integration/continuous deployment (CI/CD) pipeline. Below is a general guide on how you can achieve this using Bitbucket Pipelines and Kubernetes.
Bitbucket Pipelines is the quickest and easiest way to setup continuous delivery right from your repo if you are using bitbucket for source control. Pipelines are configured with YAML files and can be very simple or extremely complex depending on your needs.
I always prefer to split my jobs into steps:
- If a step fails, you can re-run individual steps.
- Each step is isolated from the others. Only your base repo and any “artifacts” you declare will be passed to the next step.
Steps
Configure your Bitbucket repository
- Make sure you have your project hosted on Bitbucket.
Kubernetes Cluster: Set up your Kubernetes cluster
Add your credentials and configuration settings in Bitbucket as variables. See: how to configure Pipelines variables.
Configure Kubernetes Credentials in Bitbucket
Go to repo settings, repo variables and set these up
DOCKERHUB_PASSWORD- docker hub password used for pushing the imageDOCKERHUB_USERNAME- docker hub username used for pushing the imageKUBECONFIG- authentication to kubernetes
To get the KUBECONFIG
- Switch to context
| |
- Get raw kubeconfig
| |
- Use the base64 encoded value
| |
Bitbucket pipeline Pipeline
Here is a 3-step bitbucket-pipelines.yml file that takes a nestjs app, run tests, packages it as a Docker image and deploys it to a Kubernetes cluster:
Then pipeline here in file bitbucket-pipelines.yml base of repo
| |
In the above:
- I am using helm charts
https://etowett.github.io/helm-charts
Content of dev.yml values fine
| |
Execute pipelines
Push changes to your repository, and Bitbucket Pipelines will automatically trigger the pipeline. Monitor the pipeline execution in the Bitbucket Pipelines dashboard.