Using GitHub Actions to Deploy Continuously to Kyma/Kubernetes
Using GitHub Actions to Deploy Continuously to Kyma/Kubernetes with this VS Dev Container
If you use this VS Dev Container you can follow all the steps without having to install any further program. This walkthrough only provides my additional quidance for this awesome tutorial from Marius Obert.
Preparations
- Clone this repo in a new WSL folder and start the included Dev Container
Dockerize the App
node ➜ /workspaces/sap-tech-bytes (2021-08-02-github-actions-kyma)
$ docker build -t sap-tech-bytes .
1
2
2
- Tag the image with your registry account user
node ➜ /workspaces/sap-tech-bytes (2021-08-02-github-actions-kyma)
$ docker tag dr-sap-tech-bytes:latest draschke/dr-sap-tech-bytes
output--> draschke/dr-sap-tech-bytes:latest
1
2
3
4
2
3
4
Update your .kube/config
- Update your .kube/config (after 8 hours you will have to change it again)
cp .\kubeconfig.yaml ~/.kube/config
#find your directory here
\\wsl$\Ubuntu-20.04\home\<youruser>\.kube
1
2
3
2
3
- or do it better and follow this nice guide from Marius Create a Kyma service account
The Kyma Manifest
- Make sure you are logged in to kubectl by running one of this commands
node ➜ /workspaces/sap-tech-bytes (2021-08-02-github-actions-kyma)
$ kubectl get ns
$ kubectl get pods
1
2
3
2
3
- Change the dev_deployment.yaml
#image: ghcr.io/<user>/<repo name>:latest
1
- Create secret “regcred“ (Take care that you have a namespace "tutorial")
node ➜ /workspaces/sap-tech-bytes (2021-08-02-github-actions-kyma)
$ kubectl -n tutorial create secret docker-registry regcred --docker-server=https://ghcr.io --docker-username=<github user> --docker-password=<github personal access token>
1
2
3
2
3
- After creating the secret "regcred" you'll find it here
Set up the GitHub Repository
- Go to your kubeconfig.yml and export a base64 value file and paste it to your git repository secrets
\\wsl$\Ubuntu-20.04\home\<user>\.kube\kubeconfig.yml
cat kubeconfig.yaml | base64 > base64-kubeconfig.txt
1
2
2
- Create a repo secret
DEV_KUBECONFIG
with the base64 value
Create Two GitHub Workflows
- Change the name of your image
.github/workflows/deploy.yaml
IMAGE_NAME: sap-samples/tech-bytes-kyma-cicd
1
2
2
- You need your GITHUB_TOKEN
password: ${{ secrets.GITHUB_TOKEN }}
1
- You need your DEV_KUBECONFIG
config: ${{ secrets.DEV_KUBECONFIG }}
1
This is what happen when you trigger the deployment.yaml file (.github/workflows/deploy.yaml)
- Load metadata from the Dockerfile
- Build the image
- Push the image to the registry
- Read the kubeconfig from the secret we created and deploy the image to your Kyma cluster.
- Packages on the right side
- Check if your app is running (If not keep an eye at your Pods (error logs / credentials))
Trigger the Pipeline
- Increase the version
node ➜ /workspaces/sap-tech-bytes (dr-sap-tech-bytes-2021-08-02)
$ npm version patch
v1.1.3
node ➜ /workspaces/sap-tech-bytes (dr-sap-tech-bytes-2021-08-02)
$ git push --follow-tags
...
* [new tag] v1.1.3 -> v1.1.3
1
2
3
4
5
6
7
2
3
4
5
6
7
Have had this issue:
node ➜ /workspaces/sap-tech-bytes (dr-sap-tech-bytes-2021-08-02 ✗)
$ npm version patch
Output #npm ERR! Git working directory not clean.
1
2
3
4
2
3
4
Solution:
node ➜ /workspaces/sap-tech-bytes (dr-sap-tech-bytes-2021-08-02 ✗)
$ npm version --no-git-tag-version
After that you should be fine
1
2
3
4
2
3
4
- Update the current deployment to make use of the latest image
The publish.yaml file includes a nice Action to keep your releases updated