Simple example of Azure function in Java with possibility to execute Kubernetes commands on a cluster.
Example can be easily modified, the current version shows how to delete a requested pod. Can be later used in Azure logs triggers for example (when a pod is in a broken state etc.)
Open the project in IntelliJ.
Download the Azure Toolkit for IntelliJ Plugin
You may need to upgrade your IntelliJ as some plugin functions are not available in the older versions.
Log in to Azure (Azure CLI):
Double click on Function App
and select Create
.
Setup settings for your needs.
When the function app is created, click on it and select Deploy
In the app settings add the following values:
-
AZURE_TOKEN
Usekubectl get secret
to fetch token. Get token for correct namespace with permissions (look for an account different thandefault
, default may now be allowed to execute necessary actions) -
AZURE_CLUSTER_URL
Go toKubernetes services
, select desired cluster, and inOverview
copyAPI server address
withhttps
prefix.
and click Run
.
(Deploying may take some time)
IntelliJ will display a link to your service.
You can execute an example by:
curl 'https://url/api/HttpExample?podName=(podName)&namespaceName=(namespace)
Example:
curl 'https://test-function.azurewebsites.net/api/HttpExample?podName=demo-786588bdd7-bpgfd&namespaceName=demo-namespace