Skip to content

Instantly share code, notes, and snippets.

@andrewmatveychuk
Created June 25, 2025 15:04
Show Gist options
  • Select an option

  • Save andrewmatveychuk/93d714be53ec9e625364e0e64e227fd5 to your computer and use it in GitHub Desktop.

Select an option

Save andrewmatveychuk/93d714be53ec9e625364e0e64e227fd5 to your computer and use it in GitHub Desktop.
A sample Radius recipe to provision a MySQL database as a container
@description('Information about what resource is calling this Recipe. Generated by Radius.')
param context object
@description('MySQL database name')
param database string = context.application.name
@description('MySQL username')
param user string = '${context.application.name}-user'
@description('MySQL password')
@secure()
param password string = uniqueString(context.resource.id, newGuid())
@description('MySQL root password')
@secure()
param root_password string = uniqueString(context.resource.id, newGuid())
@description('Tag to pull for the MySQL container image.')
param tag string = 'latest'
extension kubernetes with {
kubeConfig: ''
namespace: context.runtime.kubernetes.namespace
} as kubernetes
var uniqueName = 'mysql-${uniqueString(context.resource.id)}'
var port = 3306
resource mysql 'apps/Deployment@v1' = {
metadata: {
name: uniqueName
}
spec: {
selector: {
matchLabels: {
app: context.application.name
tier: 'mysql'
}
}
template: {
metadata: {
labels: {
app: context.application.name
tier: 'mysql'
'radapp.io/application': context.application == null ? '' : context.application.name
}
}
spec: {
containers: [
{
name: 'mysql'
image: 'mysql:${tag}'
ports: [
{
containerPort: port
}
]
env: [
{
name: 'MYSQL_ROOT_PASSWORD'
value: root_password
}
{
name: 'MYSQL_USER'
value: user
}
{
name: 'MYSQL_PASSWORD'
value: password
}
{
name: 'MYSQL_DATABASE'
value: database
}
]
}
]
}
}
}
}
resource svc 'core/Service@v1' = {
metadata: {
name: 'mysql'
labels: {
app: context.application.name
}
}
spec: {
type: 'ClusterIP'
selector: {
app: context.application.name
tier: 'mysql'
}
ports: [
{
port: port
}
]
}
}
output result object = {
resources: [
'/planes/kubernetes/local/namespaces/${svc.metadata.namespace}/providers/core/Service/${svc.metadata.name}'
'/planes/kubernetes/local/namespaces/${mysql.metadata.namespace}/providers/apps/Deployment/${mysql.metadata.name}'
]
values: {
host: '${svc.metadata.name}.${svc.metadata.namespace}.svc.cluster.local'
port: port
database: database
user: user
}
secrets: {
#disable-next-line outputs-should-not-contain-secrets
password: password
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment