Kubernetes Workload in GKE
This page shows how to deploy a Kubernetes workload on Google Kubernetes Engine (GKE) using the Fractal SDK.
For prerequisites, setup, and deployment file structure, see the main guide.
Java SDK
public static GoogleKubernetesEngine getGke(String id) {
return GoogleKubernetesEngine.builder()
.withId(id)
.withRegion(EU_WEST1)
.withNodePools(getNodePools())
.withK8sWorkload(getK8sWorkload())
.build();
}
public static CaaSKubernetesWorkload getK8sWorkload() {
return CaaSKubernetesWorkload.builder()
.withId("fractal-samples")
.withDescription("Fractal Service on K8S")
.withNamespace("fractal")
.withSSHRepositoryURI("git@github.com:YanchWare/fractal-samples.git")
.withRepoId("YanchWare/fractal-samples")
.withBranchName("env/prod")
.withEnvironmentSecretShortName("my-secret-name") // Add secret access
// Optional: Use a specific CI/CD profile
//.withCiCdProfileShortName("my-other-cicd-profile")
.build();
}
public static Collection<? extends GcpNodePool> getNodePools() {
return List.of(
GcpNodePool.builder()
.withName("nodes")
.withMachineType(E2_STANDARD2)
.build()
);
}
For more details, see the Custom Workload in GKE sample on GitHub.
TypeScript SDK
The cluster and the workload are two components. The blueprint declares them abstractly —
ContainerPlatform and Workload — and the Live System selects Gke and K8sWorkload.
1. Declare the cluster and workload in the blueprint
import {
createFractal,
ContainerPlatform,
Workload,
} from '@fractal_cloud/sdk/model';
export const fractal = createFractal({
id: 'gke-workload',
version: {major: 1, minor: 0, patch: 0},
description: 'Governed cluster with a custom workload.',
boundedContextId: {
ownerType: 'Personal',
ownerId: process.env['OWNER_ID']!,
name: 'reusable-templates',
},
blueprint: bp => {
const cluster = bp.add(
ContainerPlatform({id: 'app-cluster', displayName: 'Application Cluster'})
.withKubernetesVersion('1.28.5') // guardrail
.withNetworkPolicyProvider('calico') // guardrail
.withNodePools([
{name: 'nodes', minNodeCount: 1, maxNodeCount: 3, autoscalingEnabled: true},
]),
);
const app = bp.add(
Workload({id: 'app-workload', displayName: 'App Workload'})
.dependsOn(cluster),
);
return {cluster, app};
},
operations: s => ({
/** The container image the app ships. */
withImage: (image: string) => s.app.set('image', image),
/** How many replicas to run. */
withReplicas: (replicas: number) => s.app.set('replicas', replicas),
}),
});
withNodePools takes {name, minNodeCount?, maxNodeCount?, autoscalingEnabled?} — vendor-neutral
capacity, not machine types. Machine sizing is a GCP concept and does not appear on the component.
2. Select the GKE and Kubernetes-workload offers
import {Gke, K8sWorkload} from '@fractal_cloud/sdk/model';
const liveSystem = fractal
.specialize()
.withImage('europe-west1-docker.pkg.dev/my-project/apps/my-app:1.4.0')
.withReplicas(2)
.toLiveSystem({
name: 'gke-workload-dev',
environment,
select: {
'app-cluster': Gke({region: 'europe-west1'}),
'app-workload': K8sWorkload({namespace: 'default'}),
},
});
K8sWorkload is vendor-neutral: it runs on any Kubernetes cluster, so the same selection works against
AKS or an on-prem OpenShift cluster. See the Component
Reference for every parameter each offer accepts.
For more details, see the TypeScript SDK samples on GitHub.