This repository contains the setup and configuration for deploying a simple HTTP server application named Pong to a Kubernetes cluster using Flux CD.
Before getting started, make sure you have the following installed locally:
- A Kubernetes cluster (in this experiment we use Kind)
- kubectl
- Flux CLI
- GitHub Personal Access Token with repo access
- GitHub CLI
To prepare your Git repository, follow these steps:
-
Create a new directory and initialize a Git repository:
mkdir flux-experiments cd flux-experiments git init
-
Create a
manifests
directory to store Kubernetes manifests:mkdir manifests
Create the following manifest files in the manifests
directory:
-
Deployment Manifest: Create
pong-deployment.yaml
:apiVersion: apps/v1 kind: Deployment metadata: name: pong-server-deployment spec: replicas: 1 selector: matchLabels: app: pong-server template: metadata: labels: app: pong-server spec: containers: - name: pong-server image: ghcr.io/s1ntaxe770r/pong:e0fb83f27536836d1420cffd0724360a7a650c13 ports: - containerPort: 8080
-
Service Manifest: Create
pong-service.yaml
:apiVersion: v1 kind: Service metadata: name: pong-server-service spec: selector: app: pong-server ports: - protocol: TCP port: 80 targetPort: 8080
-
Add and commit these files to Git:
git add . git commit -m "Add deployment manifests"
-
Create the GitHub repository and push your changes:
gh repo create flux-experiments --source=. --remote=upstream --public git push --set-upstream upstream master
To bootstrap Flux and configure it to monitor your GitHub repository:
-
Create a Kind cluster:
kind create cluster --image kindest/node:v1.28.0 --name flux-cluster
-
Verify the state of cluster:
kubectl cluster-info --context kind-flux-cluster
-
Run pre-installation checks:
flux check --pre
-
Export your GitHub credentials:
export GITHUB_TOKEN=<your-token> export GITHUB_USER=<your-username>
-
Run the bootstrap command:
flux bootstrap github \ --owner=$GITHUB_USER \ --repository=flux-experiments \ --branch=master \ --path=clusters/my-cluster
-
Verify Flux installation:
kubectl get pods -n flux-system
-
Pull the latest changes:
git pull
To configure Flux to deploy your manifests:
-
Define a
GitRepository
resource:flux create source git pong \ --url="https://github.com/$GITHUB_USER/flux-experiments" \ --branch=master \ --interval=30s \ --export > ./clusters/my-cluster/pong-source.yaml
-
Define a
Kustomization
resource:flux create kustomization pong \ --target-namespace=default \ --source=pong \ --path="./manifests" \ --prune=true \ --interval=5m \ --export > ./clusters/my-cluster/pong-kustomization.yaml
-
Inspect the generated manifest:
cat ./clusters/my-cluster/pong-kustomization.yaml
-
Commit and push the generated manifests:
git add clusters/ git commit -m "Add kustomize manifests" git push
-
Watch Flux sync the application:
flux get kustomizations --watch
-
Verify deployment:
kubectl port-forward svc/pong-server-service 8080:80 curl http://localhost:8080/ping
To update the deployment:
-
Edit the
pong-deployment.yaml
file to increase replicas:replicas: 3
-
Save, commit, and push the changes:
git add pong-deployment.yaml git commit -m "Scale pong deployment to 3 replicas" git push origin main
-
Verify the update:
flux logs kubectl get pods
- Service Not Found: If you encounter
services "pong-server-service" not found
, verify that the service is correctly defined and deployed. - Connection Issues: Ensure the port-forwarding is correctly set up and check if the application is running properly inside the pods.
Feel free to open issues if you encounter any problems or have questions!