Phase 3: Create and deploy the application¶
Purpose¶
Create a very small application in GitHub, containerize it, and deploy it with ordinary Kubernetes manifests before introducing Argo CD. This proves the application and cluster work independently of the delivery automation.
The public source repository is
Aaronarphaxad/k8s-cicd-lab.
1. Prepare Git access on the Debian management VM¶
The management VM is where the repository SSH key lives and where application changes are made.
Create an Ed25519 key if this VM does not already have a dedicated GitHub key:
ssh-keygen -t ed25519 -C "<GitHub-email>"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub
Copy only the .pub value to GitHub > Settings > SSH and GPG keys > New SSH
key. Never copy or commit ~/.ssh/id_ed25519.
Test authentication:
GitHub normally confirms authentication while noting that it does not provide shell access.
2. Clone the empty repository and create its structure¶
After creating the empty public repository in GitHub:
git clone git@github.com:Aaronarphaxad/k8s-cicd-lab.git
cd k8s-cicd-lab
mkdir -p app tests k8s argocd .github/workflows
touch app/index.html
touch app/healthz
touch tests/test-app.sh
touch Dockerfile
touch k8s/namespace.yaml
touch k8s/deployment.yaml
touch k8s/service.yaml
touch k8s/ingress.yaml
touch argocd/application.yaml
touch .github/workflows/ci.yml
touch README.md
chmod +x tests/test-app.sh
The filenames capture the separation of concerns without repeating all of the file contents here:
k8s-cicd-lab/
├── .github/workflows/ci.yml
├── app/index.html
├── app/healthz
├── argocd/application.yaml
├── k8s/namespace.yaml
├── k8s/deployment.yaml
├── k8s/service.yaml
├── k8s/ingress.yaml
├── tests/test-app.sh
├── Dockerfile
└── README.md
The application is a static Nginx site:
/displays a visible version and later some styling./healthzreturns a small healthy response.
The test script checks the required files and expected page text. This is deliberately simple because the lab is about delivery, not application logic.
3. Commit the initial project¶
Run the local test first, then commit and push:
bash tests/test-app.sh
git status
git add .
git commit -m "Add demo application and CI workflow"
git push -u origin main
Use the repository's Actions tab to watch the test and publish jobs. Phase 4 explains each hand-off in that workflow.
4. Understand the Kubernetes manifests¶
| File | Object | Responsibility |
|---|---|---|
k8s/namespace.yaml |
Namespace | Creates the demo boundary |
k8s/deployment.yaml |
Deployment | Runs two replicas and defines probes, resources, placement, and rollout behaviour |
k8s/service.yaml |
ClusterIP Service | Gives the changing Pods one stable in-cluster name and port |
k8s/ingress.yaml |
Ingress | Routes the hostname k8s-demo.home through Traefik to the Service |
Important Deployment decisions:
replicas: 2gives one application Pod per worker under normal conditions.- The Pod selector and template labels must match.
- Readiness and liveness probes call
/healthz. - Resource requests help the scheduler; limits stop one small Pod from using the whole node.
maxUnavailable: 0keeps the old replicas available during an update.maxSurge: 1permits one temporary extra Pod during a rolling update.topologySpreadConstraintsuseskubernetes.io/hostnameso both replicas do not normally land on the same worker.- The final worker node selector matches
node-role.kubernetes.io/worker: worker.
5. Confirm the image is pullable¶
The GHCR package was made public for this lab. From a worker, test the exact
SHA-tagged image referenced by k8s/deployment.yaml:
The initial successful build corresponded to short commit 76dac6a; the
manifest uses the full SHA. A successful anonymous pull rules out registry
authentication before Kubernetes is involved.
6. Clone the repository on the control plane¶
The repository is public, so the control-plane node does not need the private SSH key from the Debian VM:
7. Apply the manifests manually¶
Apply each layer and inspect it before moving on:
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
kubectl apply -f k8s/ingress.yaml
The directory form is equivalent and was used for repeat runs:
Watch the Deployment and placement:
kubectl rollout status deployment/demo-app -n demo
kubectl get deployment,replicaset,pods -n demo -o wide
kubectl get service,ingress -n demo
The successful result was two ready replicas, one current-version Pod on each
worker, a ClusterIP Service, and a Traefik Ingress for k8s-demo.home.
8. Test inside the cluster¶
Start a temporary curl Pod and call the Service by its Kubernetes DNS name:
kubectl run curl-test \
--namespace demo \
--image=curlimages/curl:latest \
--restart=Never \
--rm \
-i \
-- curl -fsS http://demo-app/healthz
The response was:
This proves Pod DNS, the Service selector, Service routing, and the application endpoint without depending on OPNsense or Traefik.
Inspect the Service-to-Pod mapping when troubleshooting:
kubectl get service demo-app -n demo -o wide
kubectl get endpoints demo-app -n demo
kubectl get pods -n demo --show-labels
If the Endpoints list is empty, compare the Service selector with the Pod labels and check readiness probe status.
9. Add the application DNS override¶
After the Ingress existed, add an OPNsense Unbound host override under Services > Unbound DNS > Overrides:
| Field | Value |
|---|---|
| Host | k8s-demo |
| Domain | home |
| Type | A |
| Address | the selected K3s ingress node address |
| Description | K3s demo application through Traefik |
The first override pointed to one node. Save, apply, and verify from the Debian management VM and the VPN-connected laptop:
Then browse to http://k8s-demo.home while connected to WireGuard.
10. Test the other ingress node without changing DNS¶
DNS pointing to one node does not test the other node. Force the same HTTP Host header to the second worker for one request:
An equivalent test is:
Repeat with the first worker address. Both should return healthy if the
OPNsense path, node firewall, Traefik listener, Service, and Pods are healthy.
This verifies both node entry points, but it does not make DNS highly available. A production-like design would put a virtual IP or load balancer in front of the ingress nodes and point DNS to that stable address.
11. Troubleshoot the request path in layers¶
From outside to inside, check:
client DNS
-> WireGuard route
-> OPNsense WireGuard rule
-> selected node TCP 80
-> Traefik Ingress rule
-> demo-app Service
-> ready Pod endpoint
Useful commands:
getent hosts k8s-demo.home
curl -v http://k8s-demo.home/healthz
kubectl get ingress demo-app -n demo -o wide
kubectl describe ingress demo-app -n demo
kubectl get service,endpoints -n demo
kubectl get pods -n demo -o wide
kubectl logs deployment/demo-app -n demo
kubectl get pods -n kube-system -o wide | grep -E 'traefik|svclb'
If direct access to a node with the required Host header works but the hostname does not, the problem is DNS or the client route. If neither worker answers, check the OPNsense Live View and each node's firewalld rules before changing the Kubernetes manifests.
Completion checks¶
- Repository SSH access works from the Debian management VM.
- The initial application and supporting files are in Git.
- A worker can pull the public image anonymously.
- Namespace, Deployment, Service, and Ingress exist.
- Two application Pods are ready on separate workers.
- The Service responds from a temporary in-cluster Pod.
- OPNsense resolves
k8s-demo.homeinternally. - The application is reachable from the management VM and over WireGuard.
- Either ingress worker can be tested independently with the Host header.