Skip to content

mateuszwlosek/azure-functions-java-example

Repository files navigation

Azure Functions Java + Kubernetes commands example

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.)

Guide

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):
image
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
image
In the app settings add the following values:

  • AZURE_TOKEN
    Use kubectl get secret to fetch token. Get token for correct namespace with permissions (look for an account different than default, default may now be allowed to execute necessary actions)

  • AZURE_CLUSTER_URL
    Go to Kubernetes services, select desired cluster, and in Overview copy API server address with https 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