我在 survey GitHub Actions self-hosted Runner 的地端架設方式時發現 GitHub 使用 kubernetes (k8s) 的 Operator 機制做了一個可以自動根據需求動態產生/收回 runner 的解決方案,叫做 Actions Runner Controller (ARC)。
但設定上稍微複雜了點,需要先架設一個 kubernetes cluster,包含 control plane 跟 worker。
所幸外面有一個可以快速在一台機器上建立 control plane & worker 的工具,叫做 minikube。我想先把 minikube 跟 ARC 都裝好,再來試試看跟之前使用 Docker Swarm 裝的 runner 有何不同。
Day 26 試著裝 GitHub Actions Runner Controller (ARC) 失敗,我花了整個早上 troubleshooting 都無效,先來看看我都做了甚麼:
移除 podman
,改裝 Docker。
user@host:~$ minikube start
😄 minikube v1.31.2 on Ubuntu 23.04
👎 Unable to pick a default driver. Here is what was considered, in preference order:
▪ docker: Not healthy: "docker version --format {{.Server.Os}}-{{.Server.Version}}:{{.Server.Platform.Name}}" exit status 1: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version": dial unix /var/run/docker.sock: connect: permission denied
▪ docker: Suggestion: Add your user to the 'docker' group: 'sudo usermod -aG docker $USER && newgrp docker' <https://docs.docker.com/engine/install/linux-postinstall/>
💡 Alternatively you could install one of these drivers:
▪ kvm2: Not installed: exec: "virsh": executable file not found in $PATH
▪ podman: Not installed: exec: "podman": executable file not found in $PATH
▪ qemu2: Not installed: exec: "qemu-system-x86_64": executable file not found in $PATH
▪ virtualbox: Not installed: unable to find VBoxManage in $PATH
❌ Exiting due to DRV_NOT_HEALTHY: Found driver(s) but none were healthy. See above for suggestions how to fix installed drivers.
記得把 user 加入 docker
這個 user group。
最後失敗,一樣 403。
docker login
登入 GHCRPAT 權限選 read:packages
,repo
和 write:packages
。
使用 docker login
後再次嘗試安裝 helm chart arc
,失敗,一樣 403。
當嘗試從 GitHub Container Registry 拉取私有 Helm Chart 或 Docker 映像時,您可能需要一個 Personal Access Token(PAT)來進行身份驗證。下面是如何創建和使用 Personal Access Token 的步驟:
PAT 權限選 read:packages
,repo
和 write:packages
。
NAMESPACE="arc-systems"
kubectl create namespace arc-systems
kubectl create secret docker-registry github-container-registry \
--docker-server=ghcr.io \
--docker-username=## 你的 username ## \
--docker-password=## 剛剛申請的 PAT (classic)## \
--namespace=${NAMESPACE}
--set
參數指定 Image Pull Secret:helm install arc \
--namespace "${NAMESPACE}" \
--set imagePullSecrets[0].name=github-container-registry \
oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller
結果還是 403。
但奇怪的是我前天使用一樣的教學卻可以,當時其實有自己架設過標準的 Kubernetes 集群 (使用 kubectl, kubeadm, calico, helm 等)。而且成功裝起 ARC。但我後來直接給 VM Power off,導致 control plane 開不起來,準確來說是 API server 無法正常 listen 6553 port,我懷疑是因為異常關機導致 etcd 壞了?希望有人可以幫我解答一下。
這次不能安裝真的是有點傻眼,但更傻眼的是...
我休息一天,再執行一樣的指令,又正常了。
問題應該不是出在我這邊,but whatever,繼續安裝!
安裝 ARC 的 helm chart:
user@host:~$ NAMESPACE="arc-systems"
helm install arc \
--namespace "${NAMESPACE}" \
--create-namespace \
oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller
Pulled: ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller:0.6.1
Digest: sha256:4df8c76ea879375d2eb00a67a05b5bce2d483b36c386aa64767f7872201871bf
NAME: arc
LAST DEPLOYED: Fri Sep 29 14:41:58 2023
NAMESPACE: arc-systems
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Thank you for installing gha-runner-scale-set-controller.
Your release is named arc.
WARNING: value specified under image.pullPolicy will be ignored and no longer be applied to the listener pod spec as of gha-runner-scale-set-0.7.0. Please use the listenerTemplate in the gha-runner-scale-set chart to control the image pull policy of the listener.
去GitHub 產生一個 PAT (classic),權限為
- 個人 repo: repo
- 若為 Organization runners: admin:org
申請好後,將 PAT 放到 kubernetes 的 Runner Scale Set 將會處於的 namespace 內:
user@host:~$ kubectl create namespace arc-runners
namespace/arc-runners created
user@host:~$ kubectl -n arc-runners create secret generic pre-defined-secret --from-literal=github_token='-----PAT token-----'
secret/pre-defined-secret created
安裝 Runner Scale Set 的 helm chart:
user@host:~$ INSTALLATION_NAME="arc-runner-set"
NAMESPACE="arc-runners"
GITHUB_CONFIG_URL="https://github.com/repo的完整url"
GITHUB_PAT="pre-defined-secret"
helm install "${INSTALLATION_NAME}" \
--namespace "${NAMESPACE}" \
--set githubConfigUrl="${GITHUB_CONFIG_URL}" \
--set githubConfigSecret="${GITHUB_PAT}" \
oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set
Pulled: ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set:0.6.1
Digest: sha256:d0a4e067e15a2c616c6c2d049e98d9dc8e8aadb11ac6625cd01ee3ca30db8caa
NAME: arc-runner-set
LAST DEPLOYED: Fri Sep 29 15:00:36 2023
NAMESPACE: arc-runners
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Thank you for installing gha-runner-scale-set.
Your release is named arc-runner-set.
確認一下有沒有正常運作:
user@host:~$ helm list -A
NAME NAMESPACE REVISION UPDATED STATUS CHART
APP VERSION
arc arc-systems 1 2023-09-29 14:41:58.170013587 +0000 UTC deployed gha-runner-scale-set-controller-0.6.1 0.6.1
arc-runner-set arc-runners 1 2023-09-29 15:00:36.991423017 +0000 UTC deployed gha-runner-scale-set-0.6.1 0.6.1
cert-manager cert-manager 1 2023-09-29 02:59:36.226577538 +0000 UTC deployed cert-manager-v1.13.1 v1.13.1
user@host:~$ kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
arc-systems arc-gha-rs-controller-6576fcfd54-6xnwl 1/1 Running 0 32m
arc-systems arc-runner-set-754b578d-listener 1/1 Running 0 2m27s
cert-manager cert-manager-8694c7d4fd-g7z62 1/1 Running 1 (9m18s ago) 12h
cert-manager cert-manager-cainjector-744cb68868-lb2wv 1/1 Running 1 (9m18s ago) 12h
cert-manager cert-manager-webhook-5f58d6bf86-tg7wr 1/1 Running 1 (9m18s ago) 12h
kube-system coredns-5d78c9869d-4wpxb 1/1 Running 1 (9m13s ago) 12h
kube-system etcd-minikube 1/1 Running 1 (9m17s ago) 12h
kube-system kube-apiserver-minikube 1/1 Running 1 (9m17s ago) 12h
kube-system kube-controller-manager-minikube 1/1 Running 1 (9m18s ago) 12h
kube-system kube-proxy-ldwdf 1/1 Running 1 (9m18s ago) 12h
kube-system kube-scheduler-minikube 1/1 Running 1 (9m18s ago) 12h
kube-system storage-provisioner 1/1 Running 2 (2m29s ago) 12h
Repository 的 "Actions > Runners" 頁面 (不是 Runner groups) 下方會多一個 "Runner scale sets",包含 ARC 註冊的 scale set。(上方的 containerized_x runner 是 Day 19 建立的,不是 ARC 建的)
有點不解的是,scale sets 沒有打上 self-hosted
的 tag,不知考量為何,但不影響接下來的使用。
這邊 arc-runner-set 還沒有產生任何 runner,因為在 scale sets 建立好後此 repo 尚未執行任何 job。
我明天計畫一步到位,在 ARC 自動 provision 的 self-hosted runner 中執行一個在 container 執行的 job,一圓 Day 21 未完成的夢想。