This guide explains how to deploy a sample application using Flux GitOps. It demonstrates creating a simple NGINX application and testing it with MetalLB.
Prerequisites
- MetalLB Installed: Ensure MetalLB is installed and configured in your Kubernetes cluster.
- Flux Installed: Ensure Flux is installed and running in your Kubernetes cluster.
- Git Repository: A Git repository structured for Flux GitOps, e.g.,
. ├── apps/ │ └── nginx-test/ │ └── base/ ├── clusters/ │ └── production/ │ ├── apps/ <...>
1. Deploy a Sample Application
Step 1: Create the Application Manifest
File: apps/nginx-test/base/nginx-test.yaml
:
# File: apps/nginx-test/base/nginx-test.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.21
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: default
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
File: apps/nginx-test/base/kustomization.yaml
:
# File: apps/nginx-test/base/kustomization.yaml
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- nginx-test.yaml
Step 2: Reference the Application in Flux
Add the application to clusters/production/apps/kustomization.yaml
:
# File: clusters/production/apps/kustomization.yaml
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
# ...existing resources...
- ../../../apps/nginx-test/base
Commit and push the changes:
git add clusters/production/apps/kustomization.yaml
git commit -m "Add nginx-test application reference"
git push
2. Verify Deployment
Step 1: Check Flux Kustomizations
Ensure the nginx-test application is deployed:
kubectl get kustomizations -A
Step 2: Verify the Application
Check the nginx deployment and service:
kubectl get deployments -n default
kubectl get svc -n default
The nginx-service should show an EXTERNAL-IP assigned by MetalLB:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-service LoadBalancer 10.103.0.231 xxx.xxx.xxx.90 80:31568/TCP 2m
Step 3: Test the Service
Access the service using the assigned EXTERNAL-IP:
- Using curl:
curl http://<EXTERNAL-IP> # e.g. curl http://xxx.xxx.xxx.90
- Using a browser:
http://<EXTERNAL-IP>
You should see the default NGINX welcome page.
3. Cleanup
To remove the nginx-test application:
- Delete the
apps/nginx-test
directory and its references inclusters/production/apps/kustomization.yaml
. - Commit and push the changes:
git commit -m "Remove nginx-test application" git push
Flux will automatically clean up the application from the cluster.