pulumi / templates

Templates used by `pulumi new`
Apache License 2.0
100 stars 67 forks source link

[livestream] K8s templates should deploy a workload on to the cluster #566

Open jkodroff opened 1 year ago

jkodroff commented 1 year ago

Hello!

Issue details

Our K8s templates are great. I think we could make them better by deploying a workload on to the cluster after it's spun up. By doing this:

  1. We would both have something that is demo-able end-to-end without any edits whatsoever
  2. In the code, we show the user the power of using Pulumi with K8s, i.e. you can use a single tool to orchestrate everything

Affected area/feature

cnunciato commented 1 year ago

Chatting with @scottslowe, we think this feels like either a next-steps addition to the template pages or maybe an example that starts with a template and builds onto it. Thanks for bringing it up.

jkodroff commented 1 year ago

Something like this is sufficient:

const k8sProvider = new k8s.Provider("k8s-provider", {
    kubeconfig: kubeconfig,
});

const nginxDeployment = new k8s.apps.v1.Deployment("nginx-deployment", {
    metadata: {
        name: "nginx-deployment",
        labels: { app: "nginx" },
    },
    spec: {
        replicas: 1,
        selector: { matchLabels: { app: "nginx" } },
        template: {
            metadata: { labels: { app: "nginx" } },
            spec: {
                containers: [
                    {
                        name: "nginx",
                        image: "nginx:1.19.10",
                        ports: [{ containerPort: 80 }],
                    },
                ],
            },
        },
    },
}, { provider: k8sProvider });

const nginxService = new k8s.core.v1.Service("nginx-service", {
    metadata: { name: "nginx-service" },
    spec: {
        selector: { app: "nginx" },
        type: "LoadBalancer",
        ports: [{ port: 80, targetPort: 80 }],
    },
}, { provider: k8sProvider });

export const nginxLoadBalancerAddress = nginxService.status.loadBalancer.ingress[0].ip; // or .hostname if supported by the cloud in question

If we wanted to go deluxe, we could show multiple ways of deploying the same workload:

  1. K8s resources (per above)
  2. YAML files
  3. Helm Chart
  4. Helm Release
usrbinkat commented 5 months ago

With the devcontainer implemented, I recommend livestreaming this enhancement dev time.