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 start populating the Flux repository by creating a directory for our "apps". This directory is designed to contain a sub-directory for each application component:
Then create a kustomization that lets Flux know about that 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
Give the kustomization a recognizable name
Tell Flux to poll this every minute
Use the apps
path in the Git repository
Copy this file to the Git repository directory:
We'll be installing the application components using their Helm charts, which are published to Amazon ECR Public.
Let's create a HelmRepository resource to tell Flux where to source our charts:
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: retail-store
namespace: flux-system
spec:
url: oci://public.ecr.aws/aws-containers
type: "oci"
interval: 5m0s
The URL of the Helm repository
ECR Public hosts Helm charts as OCI artifacts
Check for updates every 5 minutes
Copy this file to the Git repository directory:
Finally we'll tell Flux to install the Helm chart for the ui component:
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: ui
namespace: flux-system
spec:
interval: 10m
timeout: 5m
chart:
spec:
chart: retail-store-sample-ui-chart
version: "1.2.1"
sourceRef:
kind: HelmRepository
name: retail-store
interval: 5m
releaseName: ui
install:
createNamespace: true
targetNamespace: ui
values:
ingress:
enabled: true
className: alb
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/healthcheck-path: /actuator/health/liveness
The name of the HelmRelease resource
The name and version of the chart to install, referencing the Helm repository we specified above
Create the namespace if it doesn't exist
Configure the chart using values
, in this case enabling ingress
Copy the appropriate files 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
│ ├── helm.yaml
│ └── kustomization.yaml
├── apps.yaml
└── flux-system
├── gotk-components.yaml
├── gotk-sync.yaml
└── kustomization.yaml
3 directories, 7 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
Get the URL from the Ingress resource:
k8s-ui-uinlb-a9797f0f61.elb.us-west-2.amazonaws.com
To wait until the load balancer has finished provisioning you can run this command:
And access it in your web browser. You will see the UI from the web store displayed and will be able to navigate around the site as a user.
