Portainer has released an awesome GitOps feature for end-users to boost their deployments to Portainer based on Git, and our CEO, Neil has put together an excellent blog on Portainer as part of your CI/CD Pipeline for Docker and Kubernetes. In addition to this, I wanted to share how GitHub Actions can be utilised to achieve the same results in a programmatical way.
In this blog post, I will be going through:
Note: All the artefacts used in this blog can be found in this repository.
We will need to boostrap a local Kubernetes cluster. In my case, I have utilised an Elastic Kubernetes Service (EKS) cluster in AWS, but you can use a kind, MicroK8s, K3d, minikube, or any other Kubernetes clusters.
In your Kubernetes cluster, deploy a Portainer instance using our Helm chart. Please refer to our doc for more details.
Next, let's provision GitHub Actions self-hosted runners in our local Kubernetes environment. It would be nice if Portainer can be published in the internet so that GitHub cloud managed runners can directly interact with Portainer, but that is not ideal. In case you have to, we have a blog post on how to secure Portainer.
For GitHub Actions self-hosted runners to run, there is an awesome GitHub project called actions-runner-controller operator to host these as containers. The benefits are:
In this blog post, it will use a GitHub Application for authentication, and provide self-hosted runners at an organization level. This way, the runners can be consumed by multiple repositories. Please walk-through the links thoroughly, and obtain the following:
Below are the steps to deploy our own container based self-hosted runner via Portainer:
Component | Value |
Namespace | actions-runner-system |
Name | actions-runner-portainer |
Build method | Repository (Use a git repository) |
Deployment type | Kubernetes |
Repository URL | https://github.com/portainer/examples |
Repository Reference | refs/heads/main |
Manifest Path | ./gitops/github-actions-demo/01-github-actions-runner/runner.yaml |
Automatic Updates | Enabled |
Mechanism | Polling |
Force Redeployment | Enabled |
Now, the self-hosted runners in the Kubernetes cluster is setup.
The second part is to execute a sample GitHub Actions workflow:
There you go, the application has been provisioned based on the deployments.yaml file defined in the GitHub repository. From now on, this application can strictly be controlled by following the standard Git process.
Lastly, let's scale out the number of self-hosted runners to 10:
- name: "[Portainer] Deploy a Kubernetes application"
shell: bash
run: |
echo "Executing the workflow with the id $"
sleep 300
As you can see, not only Portainer can be used to deploy applications via GUI, but it also provides APIs (The API specifications are published via Swagger) for the end users to interact with Portainer programatically.
Give Portainer a try today, experience simplified Kubernetes Operations today.