CI/CD Pipeline to OVHcloud Kubernetes with GitHub Actions
What You'll Learn
- Create a GitHub Actions workflow to:
- Build and push Docker images
- Update a deployment on OVHcloud Kubernetes
- Securely manage credentials
- Automate your deployments on every push to main
Prerequisites
- A working Kubernetes cluster on OVHcloud
- kubectl installed and kubeconfig set up
- Docker Hub or other container registry
- A GitHub repository with your app code
- GitHub Secrets configured (we'll define them next)
Set Up GitHub Secrets
In your GitHub repo, go to Settings → Secrets and variables → Actions → New repository secret and add:
| Secret Name | Description |
|---|---|
| DOCKER_USERNAME | Your Docker Hub username |
| DOCKER_PASSWORD | Your Docker Hub password or access token |
| KUBE_CONFIG_DATA | Your >kubeconfig> file, base64-encoded |
To generate KUBE_CONFIG_DATA:
cat ~/.kube/config | base64 -w 0
Make sure your kubeconfig is from the OVHcloud project you're working with.
Example App & Dockerfile
You can use the same one than from Deploy a Containerized App on OVHcloud Managed Kubernetes or your own.
Kubernetes Manifests with Image Placeholder
# k8s/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask-app
spec:
replicas: 1
selector:
matchLabels:
app: flask-app
template:
metadata:
labels:
app: flask-app
spec:
containers:
- name: flask-container
image: yourusername/ovhcloud-k8s-demo:latest
ports:
- containerPort: 5000
We’ll dynamically update the image tag in the CI workflow.
GitHub Actions Workflow File
# .github/workflows/deploy.yml
name: Build and Deploy to OVHcloud K8s
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Build and push Docker image
run: |
IMAGE=yourusername/ovhcloud-k8s-demo:${{ github.sha }}
docker build -t $IMAGE .
docker push $IMAGE
echo "IMAGE=$IMAGE" >> $GITHUB_ENV
- name: Set up kubectl
run: |
echo "${{ secrets.KUBE_CONFIG_DATA }}" | base64 -d > kubeconfig
export KUBECONFIG=$PWD/kubeconfig
kubectl version --client
- name: Update deployment with new image
run: |
kubectl set image deployment/flask-app flask-container=$IMAGE
Push & Watch It Deploy
Push your code to main and watch the GitHub Actions tab in your repository. You’ll see the image built and your Kubernetes deployment updated with the new image tag.