Skip to content

Instantly share code, notes, and snippets.

@spydx
Created August 3, 2021 21:06
Show Gist options
  • Save spydx/403c8cc0341d2ed0b1fbf933d52f0f3d to your computer and use it in GitHub Desktop.
Save spydx/403c8cc0341d2ed0b1fbf933d52f0f3d to your computer and use it in GitHub Desktop.
Pulumi new kubernetes-go
module test-project
go 1.14
require (
github.com/pulumi/pulumi-kubernetes/sdk/v3 v3.5.2
github.com/pulumi/pulumi/sdk/v3 v3.9.1
)
package main
import (
appsv1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/apps/v1"
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/core/v1"
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v3/go/kubernetes/meta/v1"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
appLabels := pulumi.StringMap{
"app": pulumi.String("nginx"),
}
deployment, err := appsv1.NewDeployment(ctx, "app-dep", &appsv1.DeploymentArgs{
Spec: appsv1.DeploymentSpecArgs{
Selector: &metav1.LabelSelectorArgs{
MatchLabels: appLabels,
},
Replicas: pulumi.Int(1),
Template: &corev1.PodTemplateSpecArgs{
Metadata: &metav1.ObjectMetaArgs{
Labels: appLabels,
},
Spec: &corev1.PodSpecArgs{
Containers: corev1.ContainerArray{
corev1.ContainerArgs{
Name: pulumi.String("nginx"),
Image: pulumi.String("nginx"),
}},
},
},
},
})
if err != nil {
return err
}
ctx.Export("name", deployment.Metadata.Elem().Name())
return nil
})
}
❯ pulumi new kubernetes-go
This command will walk you through creating a new Pulumi project.
Enter a value or leave blank to accept the (default), and press <ENTER>.
Press ^C at any time to quit.
project name: (test-project)
project description: (A minimal Kubernetes Go Pulumi program)
Created project 'test-project'
Please enter your desired stack name.
To create a stack in an organization, use the format <org-name>/<stack-name> (e.g. `acmecorp/dev`).
stack name: (dev)
Created stack 'dev'
Installing dependencies...
go: github.com/pulumi/pulumi/sdk/v3@v3.9.1 requires
github.com/spf13/cobra@v1.0.0 requires
github.com/spf13/viper@v1.4.0 requires
go.uber.org/zap@v1.10.0: verifying go.mod: go.uber.org/zap@v1.10.0/go.mod: malformed record data
error: `go mod download` failed to install dependencies; rerun manually to try again, then run 'pulumi up' to perform an initial deployment: exit status 1
❯ go mod download
go: github.com/pulumi/pulumi/sdk/v3@v3.9.1 requires
github.com/spf13/cobra@v1.0.0 requires
github.com/spf13/viper@v1.4.0 requires
go.uber.org/zap@v1.10.0: verifying go.mod: go.uber.org/zap@v1.10.0/go.mod: malformed record data
❯ go mod tidy -v
go: github.com/pulumi/pulumi/sdk/v3@v3.9.1 requires
github.com/spf13/cobra@v1.0.0 requires
github.com/spf13/viper@v1.4.0 requires
go.uber.org/zap@v1.10.0: verifying go.mod: go.uber.org/zap@v1.10.0/go.mod: malformed record data
❯ go version
go version go1.16.6 darwin/amd64
~/GIT/pulumi/test-project ────────────────────────────────────────────────────────────────────── Go 1.16.6 23:05:45
❯ pulumi version
v3.9.1
name: test-project
runtime: go
description: A minimal Kubernetes Go Pulumi program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment