Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bjnandi/self-hosted-github-actions-runner-in-kubernetes
Deploy a self-hosted GitHub Actions runner in a Kubernetes cluster to execute CI/CD workflows. The lab covers creating a custom Docker image for the runner, configuring Kubernetes deployments, and setting up GitHub Actions workflows for automated application deployment. By the end, you will deploy and verify an Nginx application in Kubernetes.
https://github.com/bjnandi/self-hosted-github-actions-runner-in-kubernetes
aws cicd cicd-pipeline deployments github github-actions k8s kubernetes nginx runner self-hosted workflow
Last synced: about 1 month ago
JSON representation
Deploy a self-hosted GitHub Actions runner in a Kubernetes cluster to execute CI/CD workflows. The lab covers creating a custom Docker image for the runner, configuring Kubernetes deployments, and setting up GitHub Actions workflows for automated application deployment. By the end, you will deploy and verify an Nginx application in Kubernetes.
- Host: GitHub
- URL: https://github.com/bjnandi/self-hosted-github-actions-runner-in-kubernetes
- Owner: bjnandi
- Created: 2024-12-29T09:28:01.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2024-12-29T15:57:47.000Z (about 1 month ago)
- Last Synced: 2024-12-29T16:25:31.313Z (about 1 month ago)
- Topics: aws, cicd, cicd-pipeline, deployments, github, github-actions, k8s, kubernetes, nginx, runner, self-hosted, workflow
- Language: Dockerfile
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Self Hosted GitHub Actions Runner in Kubernetes
Deploy a self-hosted GitHub Actions runner in a Kubernetes cluster to execute CI/CD workflows. The lab covers creating a custom Docker image for the runner, configuring Kubernetes deployments, and setting up GitHub Actions workflows for automated application deployment. By the end, you will deploy and verify an Nginx application in Kubernetes, leveraging the scalability.Step 1: Project Structure Setup
- Create a new repository:
Go to GitHub and create a new repository ( e.g., github-runner-k8s ) with a README.md file.
- Clone the repository:
```
git clone https://github.com/bjnandi/self-hosted-github-actions-runner-in-kubernetes
```
- Setup githubs default account:
```
git config user.email ""
git config user.name ""
```Step 2: Creating the Custom runner image
- Create Directory for github-runner:
```
cd github-runner-k8s
```
Step 3: Entrypoint Script
- Make the script executable:
```
chmod +x entrypoint.sh
```
Step 4: Build the docker image
- Docker Build
```
docker build \
--build-arg RUNNER_VERSION="2.302.1" \
--build-arg GITHUB_PERSONAL_TOKEN=" \
--from-literal=GITHUB_REPOSITORY= \
--from-literal=GITHUB_PERSONAL_TOKEN=
```
Step 7: Deploying to Kubernetes
- Apply the Kubernetes deployment:
```
kubectl apply -f github-runner.yaml -n host-runner
```
- Verify the deployment:
```
kubectl get pods -n host-runner
```
Step 8: Testing the Runner with Nginx Deployment
- Add GitHub Repository Secrets
Ensure the following secrets are added to your GitHub repository for secure handling:
```
DOCKER_REGISTRY: Docker registry name (e.g., Docker Hub username).
DOCKER_USERNAME: Docker Hub username.
DOCKER_PASSWORD: Docker Hub password.
KUBE_CONFIG: Kubernetes configuration file.
```- Kubernetes Configuration File
To get the KUBE_CONFIG file, you can use the following command:
```
cat /etc/rancher/k3s/k3s.yaml
```
- To get the master node ip, you can use the following command:
```
kubectl get nodes -o wide
```Step 9: Verify the Workflow
- Create a directory structure for the Nginx deployment files in your repository root directory.
```
cd ../nginx-deployment
```
- Commit and Push to Repository
After creating the required files and configuration, commit and push all files to the main branch of your repository.
```
git add --all
git commit -m "cicd-k8s"
git push
```
- Access the Application
In Poridhi's Kubernetes cluster verify the deploymets and services
```
kubectl get namespaces
````
- For successful deployment, you should see the dev namespace.
```
kubectl get deployments -n dev
```
- For successful deployment, you should see the nginx-deployment.
```
kubectl get services -n dev
```
- Now to access the application, you should get the etho ip of the master node and the nodeport of the service.To get the eth0 ip of the master node, you can use the following command:
```
ifconfig
```
- Access the Application:
```
curl ip-address:30080
```Congratulations!! You have successfully set up a self-hosted runner in Kubernetes and deployed an Nginx application using GitHub Actions. You have learned how to automate the Docker build, Kubernetes deployment, and service creation using GitHub workflows. By leveraging self-hosted runners, you can optimize resource usage and streamline CI/CD processes in Kubernetes environments.
For more Details:
https://poridhi.io/lab-group-modules/676a65139561ceed0084a234/676a80c3b4d4aa86d481e56f