How-To: Set up Radius with Flux
Categories:
This guide will provide an overview of how to:
- Set up Radius with Flux for GitOps
- Configure Flux to manage your Radius application
- Deploy your Radius application using Flux
Prerequisites
- Supported Kubernetes cluster
- rad CLI
- Radius environment
- A remote Git repository (e.g., GitHub, GitLab, etc.) to store your application files
- Flux CLI
- Flux control plane components installed in your Kubernetes cluster
⚠️ Flux Network PolicyWhen installing Flux using theflux bootstraporflux installcommands, ensure that the--network-policy falseflag is specified, or that the network policy is configured to allow access fromradius-systemnamespace to the source controller. This is important for the Flux source controller to be able to communicate with your Git repository and sync changes effectively. For more information on the network policy, see the Flux documentation.
Step 1: Create a Git Repository
- 
Create a new directory for your application: mkdir radius-flux-app cd radius-flux-app
- 
Initialize a new Git repository and sync it with your remote repository: git init git add . git remote add origin <your-repo-url>
Step 2: Prepare Application for Deployment by Flux
- 
Create a new Bicep file named app.bicepin theradius-flux-appdirectory. This file will define your application resources. Here is an example of a simple application that deploys a demo container:// Import the set of Radius resources (Applications.*) into Bicep extension radius @description('The Radius environment name to deploy the application and resources to.') param environment string = 'default' resource env 'Applications.Core/environments@2023-10-01-preview' existing = { name: environment } resource app 'Applications.Core/applications@2023-10-01-preview' = { name: 'app' properties: { environment: env.id } } resource demo 'Applications.Core/containers@2023-10-01-preview' = { name: 'demo' properties: { application: app.id container: { image: 'ghcr.io/radius-project/samples/demo:latest' ports: { web: { containerPort: 3000 } } } } }Next, we will create a configuration file in our repository to inform Radius about which Bicep files to deploy. This file is named radius-gitops-config.yamland it will be created in the same directory as yourapp.bicepfile.Create a new file named radius-gitops-config.yamland add the following content:config: - name: app.bicep resourceGroup: defaultFinally, commit and push your changes to the Git repository: git add app.bicep radius-gitops-config.yaml git commit -m "Add Radius application and configuration for Flux" git push origin main
Step 3: Configure Flux to Manage Your Application
- 
Register your Git repository with Flux: flux create source git radius-flux-app \ --url=<your-repo-url> \ --branch=mainNow, Flux will monitor your Git repository for changes and Radius will deploy the application automatically when changes are detected. 💡 Flux SyncYou can manually trigger a sync in Flux by running the following command: flux reconcile source git radius-flux-appThis will force Flux to check for changes in the Git repository and deploy any updates to your Kubernetes cluster. After some time, you should be able to see the resources in your Kubernetes cluster: ❯ kubectl get pods -A ... NAMESPACE NAME READY STATUS RESTARTS AGE default-app demo-56d7fd6b64-q95sl 1/1 Running 0 27s ...You can also use rad app graphto visualize the resources created by your application:❯ rad app graph -a app Displaying application: app Name: demo (Applications.Core/containers) Connections: (none) Resources: demo (apps/Deployment) demo (core/Service) demo (core/ServiceAccount) demo (rbac.authorization.k8s.io/Role) demo (rbac.authorization.k8s.io/RoleBinding)💡 Debugging Radius + GitOpsBehind the scenes, Radius will create a custom resource called DeploymentTemplateto represent your Bicep deployment. You can check the status of this resource to see if there are any issues with the deployment:❯ kubectl get deploymenttemplates -A NAMESPACE NAME STATUS app app.bicep Ready ❯ kubectl describe deploymenttemplate app.bicep -n app ...
Step 5: Update Your Application
Now that your application is registered with Flux, you can make changes to your application definitions and push them to your Git repository. Flux and Radius will do the rest - automatically detecting the changes and deploying them to your Kubernetes cluster.
- 
Open app.bicepand make some changes to the application definition. For example, you can specify parameters and increase the number of replicas for the demo container:// Import the set of Radius resources (Applications.*) into Bicep extension radius @description('The Radius environment name to deploy the application and resources to.') param environment string @description('The number of replicas to deploy for the demo container.') param replicas string resource env 'Applications.Core/environments@2023-10-01-preview' existing = { name: environment } resource app 'Applications.Core/applications@2023-10-01-preview' = { name: 'app' properties: { environment: env.id } } resource demo 'Applications.Core/containers@2023-10-01-preview' = { name: 'demo' properties: { application: app.id container: { image: 'ghcr.io/radius-project/samples/demo:latest' ports: { web: { containerPort: 3000 } } } extensions: [ { kind: 'manualScaling' replicas: int(replicas) } ] } }
- 
Add a new file app.bicepparamto define the parameters for your application:using 'app.bicep' param environment = 'default' param replicas = '3'
- 
Update the radius-gitops-config.yamlfile to include the new parameter file:config: - name: app.bicep params: app.bicepparam resourceGroup: default
- 
As before, commit and push your changes to the Git repository: git add app.bicep app.bicepparam radius-gitops-config.yaml git commit -m "Update application definition and parameters" git push origin mainAfter some time (Flux needs to reconcile the Git repository), you should be able to see that the application has been scaled up to 3 replicas: ❯ kubectl get pods -A NAMESPACE NAME READY STATUS RESTARTS AGE ... default-app demo-56d7fd6b64-6zwj7 1/1 Running 0 2m19s default-app demo-56d7fd6b64-n9rqz 1/1 Running 0 2m19s default-app demo-56d7fd6b64-q95sl 1/1 Running 0 13m ...
Done
Congratulations! You have successfully integrated Radius with Flux for GitOps. You can now manage your Radius applications using Git as the single source of truth.
Cleanup
To cleanup the resources created in this guide, you can update the radius-gitops-config.yaml to remove the Bicep file entries in the radius-gitops-config.yaml file.
Before:
config:
  - name: app.bicep
    params: app.bicepparam
    resourceGroup: default
After:
config: 
   # intentionally empty - no Bicep files to deploy.
Then, commit the changes:
```bash
rm app.bicep
rm app.bicepparam
git add app.bicep app.bicepparam radius-gitops-config.yaml
git commit -m "Remove application files"
git push origin main
After some time, you should see that the resources have been removed from your Kubernetes cluster.
Feedback
Was this page helpful?
Glad to hear it! Please feel free to star our repo and join our Discord server to stay up to date with the project.
Sorry to hear that. If you would like to also contribute a suggestion visit and tell us how we can improve.