Pulumi Java: Deploying a Minecraft Server on Azure AKS

Cloud Native Pilgrim | Kubernetes Enthusiast | Serverless Believer | Customer Experience Architect @ Pulumi | (he/him) | CK{A,AD} |
Search for a command to run...

Cloud Native Pilgrim | Kubernetes Enthusiast | Serverless Believer | Customer Experience Architect @ Pulumi | (he/him) | CK{A,AD} |
No comments yet. Be the first to comment.
GPU scheduling in Kubernetes has always felt like buying a mansion when you need a studio apartment. A small inference workload that needs 2GB of GPU memory gets scheduled on an entire 80GB A100, and there's nothing you can do about it. The device pl...

TL;DR: The code https://github.com/dirien/quick-bites Nothing is more controversial in the Kubernetes community than whether to use Helm or Kustomize. I always advocate the philosophy of using the right tool for the right job. It avoids the problem...

TL;DR Le code https://github.com/dirien/quick-bites Introduction This article is part three of my series on secret management on Kubernetes with the help of Pulumi. In my first article, we talked about the Sealed Secrets controller. The second arti...

With AWS Lambda

Disaster Recovery, Data Migration made easy!

Here you go:
This is a very short introduction to the new Pulumi Java language support. Pulumi supports writing your infrastructure as code using the Java language. Java 11 or later is required.
We are going to create an AKS cluster and deploy a Minecraft server via the use of a Helm chart. All in Pulumi and all in Java.
We use the new java template to create the scaffolding for our application.
pulumi new java --force
# It may be necessary to install the java language plugin
pulumi plugin install language java
Add the java dependency for Azure and Kubernetes to your projects pom.xml file:
...
<dependencies>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>pulumi</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>azure-native</artifactId>
<version>1.63.0</version>
</dependency>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>azuread</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>com.pulumi</groupId>
<artifactId>kubernetes</artifactId>
<version>3.18.3</version>
</dependency>
</dependencies>
...
You can find the details about the providers in the registry documentation:
Here are some snippets of the code, you can find the full code in the repo link on the top of this article:
package minecraft;
import com.pulumi.Pulumi;
import com.pulumi.azuread.*;
import com.pulumi.azurenative.containerservice.ContainerserviceFunctions;
import com.pulumi.azurenative.containerservice.ManagedCluster;
....
public static void main(String[] args) {
Pulumi.run(ctx -> {
ResourceGroup minecraftGroup = new ResourceGroup("minecraft-java-resource-group",
ResourceGroupArgs.builder()
.resourceGroupName("minecraft-java-rg")
.location("westeurope")
.build());
Application application = new Application("minecraft-app",
ApplicationArgs.builder()
.displayName("minecraft").build());
ServicePrincipal servicePrincipal = new ServicePrincipal("minecraft-java-sp",
ServicePrincipalArgs.builder()
.applicationId(application.applicationId()).build());
ServicePrincipalPassword ServicePrincipalPassword = new ServicePrincipalPassword("minecraft-java-sp-pw",
ServicePrincipalPasswordArgs.builder()
.servicePrincipalId(servicePrincipal.getId())
.endDate("2099-01-01T00:00:00Z").build());
ManagedCluster mc = new ManagedCluster("minecraft-aks",
ManagedClusterArgs.builder()
.kubernetesVersion("1.23.5")
.location(minecraftGroup.location())
.resourceGroupName(minecraftGroup.name())
.resourceName("minecraft-aks")
.nodeResourceGroup("minecraft-aks-nodes")
.dnsPrefix(minecraftGroup.name())
.enableRBAC(true)
.servicePrincipalProfile(ManagedClusterServicePrincipalProfileArgs.builder()
.clientId(application.applicationId())
.secret(ServicePrincipalPassword.value()).build())
.agentPoolProfiles(new ManagedClusterAgentPoolProfileArgs[]
{ManagedClusterAgentPoolProfileArgs.builder()
.count(3)
.vmSize("Standard_B2ms")
.osType("Linux")
.osDiskSizeGB(30)
.mode("System")
.name("agentpool").build()}).build());
...
ctx.export("kubeconfig", ctx.output(kubeconfig).asSecret());
Provider provider = new Provider("minecraft-k8s-provider",
ProviderArgs.builder()
.kubeconfig(kubeconfig).build(),
CustomResourceOptions.builder()
.parent(mc).build());
new Release("minecraft",
ReleaseArgs.builder()
.chart("minecraft")
.namespace("minecraft")
.createNamespace(true)
.version("3.10.0")
.valueYamlFiles(new com.pulumi.asset.FileAsset("./values.yaml"))
.repositoryOpts(RepositoryOptsArgs.builder()
.repo("https://itzg.github.io/minecraft-server-charts").build()).build(),
CustomResourceOptions.builder()
.provider(provider)
.parent(provider).build());
});
}
}
Now you can run our program via the call:
pulumi up
...
Previewing update (dev)
View Live: https://app.pulumi.com/dirien/pulumi-java-azure-kubernetes/dev/previews/0b6ffbd0-9311-482b-9834-5039bab277df
Type Name Plan
+ pulumi:pulumi:Stack pulumi-java-azure-kubernetes-dev create
+ ├─ azuread:index:Application minecraft-app create
+ ├─ azure-native:resources:ResourceGroup minecraft-java-resource-group create
+ ├─ azuread:index:ServicePrincipal minecraft-java-sp create
+ ├─ azuread:index:ServicePrincipalPassword minecraft-java-sp-pw create
+ └─ azure-native:containerservice:ManagedCluster minecraft-aks create
+ └─ pulumi:providers:kubernetes minecraft-k8s-provider create
+ └─ kubernetes:helm.sh/v3:Release minecraft create
Resources:
+ 8 to create

The kubeconfig you can export via the commmand:
pulumi stack output kubeconfig --show-secrets > kubeconfig.yaml
Check for the external ip and use this to enter in your Minecraft client:

Have fun!

Of course we going to destroy our application, with the following command:
pulumi destroy