I’m writing a Github action to build a docker image and deploy it to a k8s cluster, and currently am having to build, push the image to a repo, and then kubectl apply
in the standard way to deploy it.
I have set up a self-hosted GitHub actions runner using ARC (actions-runner-controller) to run on my k8s cluster. Since the runner doing the work itself lives on the cluster, is there any way I can build the image and then immediately deploy it to the cluster, without having to push and pull to a repo only to get back to where the image was built in the first place?
2
Answers
What you want to do is below
build container image inside container
without push and pull process, use builded image to change or deploy it to k8s cluster
To do this, you need to know about
1. DIND (Docker in Docker) <- to build image inside a container
Need privileged options to run dind
2. RBAC (for deploy or change your image by using kubectl on your cluster)
your github action runner need role to deploy on your kubernetes
make serviceaccount,role (or clusterrole) and bind it to your runner
Examples
serviceaccounts
Role ( or ClusterRole)
3. Proper Workflow setup and image name on github actions
you also need kubeconfig to use kubectl
And deployment’s imagepullPolicy has to be set ifNotPresent
Examples
This depends on your workflow, but I think using a repo is more sufficient and useful in the long run. You may use the following tools on creating your image:
Kaniko
Skopeo