Deploying an application
We have successfully bootstrapped Flux on our cluster so now we can deploy an application. To demonstrate the difference between a GitOps-based delivery of an application and other methods, we'll migrate the UI component of the sample application which is currently using the kubectl apply -k
approach to the new Flux deployment approach.
First let's remove the existing UI component so we can replace it:
Next, clone the repository we used to bootstrap Flux in the previous section:
Now, let's get into the cloned repository and start creating our GitOps configuration. Copy the existing kustomize configuration for the UI service:
We'll then need to create a kustomization in the apps
directory:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ui
Copy this file to the Git repository directory:
The last step before we push our changes is to ensure that Flux is aware of our apps
directory. We do that by creating an additional file in the flux
directory:
apiVersion: kustomize.toolkit.fluxcd.io/v1beta1
kind: Kustomization
metadata:
name: apps
namespace: flux-system
spec:
interval: 1m0s
sourceRef:
kind: GitRepository
name: flux-system
path: ./apps
prune: true
validation: client
Copy this file to the Git repository directory:
You Git directory should now look something like this which you can validate by running tree ~/environment/flux
:
.
├── apps
│ ├── kustomization.yaml
│ └── ui
│ ├── configMap.yaml
│ ├── deployment.yaml
│ ├── kustomization.yaml
│ ├── namespace.yaml
│ ├── serviceAccount.yaml
│ └── service.yaml
├── apps.yaml
└── flux-system
├── gotk-components.yaml
├── gotk-sync.yaml
└── kustomization.yaml
3 directories, 11 files
Finally we can push our configuration to CodeCommit:
It will take Flux some time to notice the changes in CodeCommit and reconcile. You can use the Flux CLI to watch for our new apps
kustomization to appear:
NAMESPACE NAME AGE READY STATUS
flux-system flux-system 14h True Applied revision: main/f39f67e6fb870eed5997c65a58c35f8a58515969
flux-system apps 34s True Applied revision: main/f39f67e6fb870eed5997c65a58c35f8a58515969
You can also manually trigger Flux to reconcile like so:
Once apps
appears as indicated above use Ctrl+C
to close the command. You should now have all the resources related to the UI services deployed once more. To verify, run the following commands:
NAME READY UP-TO-DATE AVAILABLE AGE
ui 1/1 1 1 5m
NAME READY STATUS RESTARTS AGE
ui-54ff78779b-qnrrc 1/1 Running 0 5m
We've now successfully migrated the UI component to deploy using Flux, and any further changes pushed to the Git repository will be automatically reconciled to our EKS cluster.