• Stars
    star
    105
  • Rank 316,772 (Top 7 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created almost 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Upgrade your Kubernetes YAML to a modern language

kube2pulumi

Convert Kubernetes YAML to Pulumi programs in Go, TypeScript, Python, C# and Java. Improve your Kubernetes development experience by taking advantage of strong types, compilation errors, full IDE support for features like autocomplete. Declare and manage the infrastructure in any cloud in the same program that manages your Kubernetes resources.

Live Demo

Check out the kube2pulumi web app to see kube2pulumi in action in your browser.

Prerequisites

  1. Pulumi CLI
  2. Install the Pulumi Kubernetes plugin:
$ pulumi plugin install resource kubernetes v3.0.0

Building and Installation

If you wish to use kube2pulumi without developing the tool itself, you can use one of the binary releases hosted on GitHub.

Homebrew

kube2pulumi can be installed on Mac from the Pulumi Homebrew tap.

brew install pulumi/tap/kube2pulumi

kube2pulumi uses Go modules to manage dependencies. If you want to develop kube2pulumi itself, you'll need to have Go installed in order to build. Once this prerequisite is installed, run the following to build the kube2pulumi binary and install it into $GOPATH/bin:

$ go build -o $GOPATH/bin/kube2pulumi -ldflags="-X github.com/pulumi/kube2pulumi/pkg/version.Version=1.0.0" cmd/kube2pulumi/main.go

The ldflags argument is necessary to dynamically set the kube2pulumi version at build time. However, the version itself can be anything, so you don't have to set it to dev.

Go should automatically handle pulling the dependencies for you. If $GOPATH/bin is not on your path, you may want to move the kube2pulumi binary from $GOPATH/bin into a directory that is on your path.

Usage

In order to use kube2pulumi to convert Kubernetes YAML to Pulumi and then deploy it, you'll first need to install the Pulumi CLI.

Once the Pulumi CLI has been installed, you'll need to install the Kubernetes plugin:

$ pulumi plugin install resource kubernetes v2.4.2

Now, navigate to the same directory as the the YAML you'd like to convert and create a new Pulumi stack in your favorite language:

// For a Go project
$ pulumi new kubernetes-go -f

// For a TypeScript project
$ pulumi new kubernetes-typescript -f

// For a Python project
$ pulumi new kubernetes-python -f

// For a C# project
$ pulumi new kubernetes-csharp -f

// For a Java project
$ pulumi new kubernetes-java -f

Then run kube2pulumi which will write a file in the directory that contains the Pulumi project you just created:

// For a Go project
$ kube2pulumi go 

// For a TypeScript project
$ kube2pulumi typescript

// For a Python project
$ kube2pulumi python

// For a C# project
$ kube2pulumi csharp

// For a Java project
$ kube2pulumi java

This will generate a Pulumi program that when run with pulumi update will deploy the Kubernetes resources originally described by your YAML. Note that before deployment you will need to configure Kubernetes so the Pulumi CLI can connect to a Kubernetes cluster. If you have previously configured the kubectl CLI, kubectl, Pulumi will respect and use your configuration settings.

Example

Let's convert a simple YAML file describing a pod with a single container running nginx:

apiVersion: v1
kind: Pod
metadata:
  namespace: foo
  name: bar
spec:
  containers:
    - name: nginx
      image: nginx:1.14-alpine
      resources:
        limits:
          memory: 20Mi
          cpu: 0.2

Go

kube2pulumi go -f ./pod.yaml
package main

import (
	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 {
		_, err := corev1.NewPod(ctx, "fooBarPod", &corev1.PodArgs{
			ApiVersion: pulumi.String("v1"),
			Kind:       pulumi.String("Pod"),
			Metadata: &metav1.ObjectMetaArgs{
				Namespace: pulumi.String("foo"),
				Name:      pulumi.String("bar"),
			},
			Spec: &corev1.PodSpecArgs{
				Containers: corev1.ContainerArray{
					&corev1.ContainerArgs{
						Name:  pulumi.String("nginx"),
						Image: pulumi.String("nginx:1.14-alpine"),
						Resources: &corev1.ResourceRequirementsArgs{
							Limits: pulumi.StringMap{
								"memory": pulumi.String("20Mi"),
								"cpu":    pulumi.String("0.2"),
							},
						},
					},
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}

TypeScript

kube2pulumi typescript -f ./pod.yaml
import * as pulumi from "@pulumi/pulumi";
import * as kubernetes from "@pulumi/kubernetes";

const fooBarPod = new kubernetes.core.v1.Pod("fooBarPod", {
    apiVersion: "v1",
    kind: "Pod",
    metadata: {
        namespace: "foo",
        name: "bar",
    },
    spec: {
        containers: [{
            name: "nginx",
            image: "nginx:1.14-alpine",
            resources: {
                limits: {
                    memory: "20Mi",
                    cpu: 0.2,
                },
            },
        }],
    },
});

Python

kube2pulumi python -f ./pod.yaml
import pulumi
import pulumi_kubernetes as kubernetes

foo_bar_pod = kubernetes.core.v1.Pod("fooBarPod",
    api_version="v1",
    kind="Pod",
    metadata={
        "namespace": "foo",
        "name": "bar",
    },
    spec={
        "containers": [{
            "name": "nginx",
            "image": "nginx:1.14-alpine",
            "resources": {
                "limits": {
                    "memory": "20Mi",
                    "cpu": "0.2",
                },
            },
        }],
    })

C#

kube2pulumi csharp -f ./pod.yaml
using Pulumi;
using Kubernetes = Pulumi.Kubernetes;

class MyStack : Stack
{
    public MyStack()
    {
        var fooBarPod = new Kubernetes.Core.V1.Pod("fooBarPod", new Kubernetes.Types.Inputs.Core.V1.PodArgs
        {
            ApiVersion = "v1",
            Kind = "Pod",
            Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs
            {
                Namespace = "foo",
                Name = "bar",
            },
            Spec = new Kubernetes.Types.Inputs.Core.V1.PodSpecArgs
            {
                Containers = 
                {
                    new Kubernetes.Types.Inputs.Core.V1.ContainerArgs
                    {
                        Name = "nginx",
                        Image = "nginx:1.14-alpine",
                        Resources = new Kubernetes.Types.Inputs.Core.V1.ResourceRequirementsArgs
                        {
                            Limits = 
                            {
                                { "memory", "20Mi" },
                                { "cpu", "0.2" },
                            },
                        },
                    },
                },
            },
        });
    }

}

Java

kube2pulumi java -f ./pod.yaml
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.kubernetes.core_v1.Pod;
import com.pulumi.kubernetes.core_v1.PodArgs;
import com.pulumi.kubernetes.meta_v1.inputs.ObjectMetaArgs;
import com.pulumi.kubernetes.core_v1.inputs.PodSpecArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var fooBarPod = new Pod("fooBarPod", PodArgs.builder()
                .apiVersion("v1")
                .kind("Pod")
                .metadata(ObjectMetaArgs.builder()
                        .namespace("foo")
                        .name("bar")
                        .build())
                .spec(PodSpecArgs.builder()
                        .containers(ContainerArgs.builder()
                                .name("nginx")
                                .image("nginx:1.14-alpine")
                                .resources(ResourceRequirementsArgs.builder()
                                        .limits(Map.ofEntries(
                                                Map.entry("memory", "20Mi"),
                                                Map.entry("cpu", 0.2)
                                        ))
                                        .build())
                                .build())
                        .build())
                .build());

    }
}

Limitations

kube2pulumi currently does not handle the conversion of CustomResourceDefinitions or CustomResources. However, our new tool crd2pulumi, creates strongly-typed args for a Resource based on your CRD! If using CRD/CR's make sure to check out the following tool!

  1. crd2pulumi README

More Repositories

1

pulumi

Pulumi - Infrastructure as Code in any programming language. Build infrastructure intuitively on any cloud using familiar languages 🚀
Go
19,033
star
2

kubespy

Tools for observing Kubernetes resources in real time, powered by Pulumi.
Go
2,689
star
3

examples

Infrastructure, containers, and serverless apps to AWS, Azure, GCP, and Kubernetes... all deployed with Pulumi
TypeScript
2,074
star
4

pulumi-aws

An Amazon Web Services (AWS) Pulumi resource package, providing multi-language access to AWS
Java
358
star
5

pulumi-kubernetes

A Pulumi resource provider for Kubernetes to manage API resources and workloads in running clusters
Java
358
star
6

tf2pulumi

A tool to convert Terraform projects to Pulumi
Go
291
star
7

actions

Deploy continuously to your cloud of choice, using your favorite language, Pulumi, and GitHub!
TypeScript
227
star
8

pulumi-ai

TypeScript
221
star
9

pulumi-kubernetes-operator

A Kubernetes Operator that automates the deployment of Pulumi Stacks
Go
196
star
10

automation-api-examples

Examples for the Pulumi Automation API https://pkg.go.dev/github.com/pulumi/pulumi/sdk/v3/go/auto?tab=doc
Go
191
star
11

esc

Pulumi ESC (Environments, Secrets, and Configuration) for cloud applications and infrastructure.
Go
185
star
12

pulumi-awsx

AWS infrastructure best practices in component form!
TypeScript
178
star
13

pulumi-eks

A Pulumi component for easily creating and managing an Amazon EKS Cluster
Java
154
star
14

pulumi-terraform-bridge

A library allowing providers built with the Terraform Plugin SDK to be bridged into Pulumi.
Go
145
star
15

pulumi-gcp

A Google Cloud Platform (GCP) Pulumi resource package, providing multi-language access to GCP
Java
145
star
16

pulumi-kubernetesx

Kubernetes for Everyone
TypeScript
129
star
17

pulumi-azure

A Microsoft Azure Pulumi resource package, providing multi-language access to Azure
Java
123
star
18

docs

All things related to docs generation for the Pulumi CLI, SDK, and tutorials.
HTML
119
star
19

pulumi-azure-native

Azure Native Provider
114
star
20

pulumi-cloud

A highly productive multi-cloud framework for containers, serverless, and data
TypeScript
113
star
21

pulumi-terraform

A resource package that allows Pulumi programs to use Terraform state
Go
106
star
22

infrastructure-as-code-workshop

Infrastructure as Code Workshop
C#
92
star
23

pulumi-aws-native

AWS Native Provider for Pulumi
Go
84
star
24

kubernetes-guides

Crosswalk Playbooks and Code for Teams to Manage Kubernetes in Production
TypeScript
80
star
25

crd2pulumi

Generate typed CustomResources from a Kubernetes CustomResourceDefinition
Go
74
star
26

workshops

A definitive place to store all the Pulumi workshops
Python
65
star
27

pulumi-google-native

Python
64
star
28

pulumi-cloudflare

Pulumi's Cloudflare package, providing multi-language infrastructure as code for Cloudflare
Java
63
star
29

pulumi-java

Java support for Pulumi
Java
61
star
30

pulumi-cdk

Pulumi/CDK Interop Library
TypeScript
60
star
31

pulumi-docker

A Docker Pulumi resource package, providing multi-language access to Docker resources and building images.
Java
60
star
32

templates

Templates used by `pulumi new`
Go
58
star
33

pulumi-tf-provider-boilerplate

Boilerplate code for Terraform provider-backed Pulumi packages
Go
57
star
34

pulumi-command

Java
54
star
35

pulumi-alicloud

An AliCloud Pulumi resource package, providing multi-language access to AliCloud
Go
48
star
36

pulumi-vsphere

A Pulumi resource package for VMWare VSphere, providing multi-language access to vCenter Server and ESXi
Java
46
star
37

setup-pulumi

GitHub Action to install the Pulumi CLI
TypeScript
45
star
38

pulumi-provider-boilerplate

Boilerplate showing how to create a native Pulumi provider
Python
42
star
39

pulumi-openstack

An OpenStack Pulumi resource package, providing multi-language access to OpenStack
Java
39
star
40

pulumi-github

A Pulumi package to facilitate interacting with GitHub
Java
39
star
41

pulumi-yaml

YAML language provider for Pulumi
Go
35
star
42

pulumi-hcloud

A Hetzner Cloud Pulumi resource package, providing multi-language access to Hetzner Cloud
Java
32
star
43

pulumi-hugo

A Hugo module containing content and layouts used on pulumi.com, including hand-authored docs, the Pulumi blog, and Learn Pulumi.
CSS
30
star
44

pulumi-azure-nextgen

Next generation Microsoft Azure provider for Pulumi, providing multi-language access to Azure
29
star
45

pulumi-random

A Pulumi provider that safely enables randomness for resources
Java
29
star
46

pulumi-policy

Pulumi's Policy as Code SDK, CrossGuard. Define infrastructure checks in code to enforce security, compliance, cost, and other practices, enforced at deployment time.
TypeScript
28
star
47

pulumi-self-hosted-installers

Repository for getting started with self-hosted Pulumi Service.
TypeScript
27
star
48

pulumi-keycloak

A KeyCloak Pulumi resource package, providing multi-language access to KeyCloak
Java
27
star
49

pulumi-postgresql

A Postgresql Pulumi resource package
Go
27
star
50

pulumi-go-provider

A framework for building Go Providers for Pulumi
Go
26
star
51

registry

The global index of everything you can do with Pulumi.
TypeScript
24
star
52

pulumictl

A swiss army knife for Pulumi development
Go
24
star
53

pulumi-policy-aws

A policy pack of rules to enforce AWS best practices for security, reliability, cost, and more!
TypeScript
24
star
54

pulumi-oci

An Oracle Cloud (OCI) Pulumi resource package, providing multi-language access to OCI
Go
23
star
55

pulumi-dotnet

.NET support for Pulumi
C#
23
star
56

pulumi-libvirt

Java
23
star
57

pulumi-linode

Linode resource provider for Pulumi
Java
23
star
58

pulumi-component-provider-ts-boilerplate

Go
22
star
59

pulumi-auth0

An auth0Pulumi resource package, providing multi-language access to Auth0
Go
22
star
60

pulumi-vault

A Vault Pulumi resource package, providing multi-language access to HashiCorp Vault
Go
21
star
61

pulumi-lsp

A LSP server for Pulumi YAML
Go
20
star
62

pulumi-az-pipelines-task

Azure Pipelines task extension for running Pulumi apps.
TypeScript
20
star
63

circleci

CircleCI Orbs for CI/CD using Pulumi.
JavaScript
19
star
64

pulumi-gitlab

A GitLab Pulumi resource package, providing multi-language access to GitLab
Java
18
star
65

halloumi

Go
17
star
66

actions-example-gke-rails

Deploys a Dockerized Rails app to Kubernetes on Google, using GitHub Actions and Pulumi
HTML
17
star
67

pulumi-azuredevops

An AzureDevOps Pulumi resource package, providing multi-language access to AzureDevOps
Go
16
star
68

pulumi-component-provider-py-boilerplate

Demonstrates building a multi-lang Pulumi component provider in Python
Python
16
star
69

pulumitv

Projects and examples related to Pulumi TV
TypeScript
15
star
70

pulumi-aws-serverless

Easy serverless programming for AWS
TypeScript
15
star
71

pulumi-datadog

An Datadog Pulumi resource package, providing multi-language access to Datadog
Go
15
star
72

pulumi-azuread

A Microsoft Azure Active Directory (Azure AD) Pulumi resource package, providing multi-language access to Azure AD
Java
15
star
73

pulumi-snowflake

Go
15
star
74

pulumi-docker-containers

Definitions for official Pulumi Docker images.
Dockerfile
14
star
75

eks-blueprint

Go
14
star
76

pulumi-component-provider-go-boilerplate

Go
14
star
77

pulumi-backstage-plugin

Pulumi plugin for Backstage
TypeScript
14
star
78

compliance-policies

A library of policies for Pulumi's Policy as Code
TypeScript
14
star
79

pulumi-yandex

Python
13
star
80

pulumi-kubernetes-cert-manager

A Pulumi Kubernetes CertManager component
Java
13
star
81

pulumi-pulumiservice

Go
12
star
82

pulumi-mongodbatlas

A MongoDB Atlas Pulumi resource package, providing multi-language access to MongoDB Atlas
Java
12
star
83

pulumi-tailscale

Go
12
star
84

pulumi-aiven

An Aiven Pulumi resource package, providing multi-language access to Aiven
Go
12
star
85

pulumi-kafka

A Kafka Pulumi resource package, providing multi-language access to Kafka
Java
12
star
86

pulumi-databricks

Go
12
star
87

actions-pulumify

Pulumify - A GitHub Action to continuously deploy static website previews
Python
11
star
88

pulumi-kubernetes-ingress-nginx

A Pulumi NGINX Ingress Controller component
Python
11
star
89

pulumi-policy-opa

A bridge enabling Pulumi CrossGuard to run OPA rules
Go
11
star
90

pulumi-cloud-requests

Welcome to the public issue tracker for Pulumi Cloud (app.pulumi.com)! Feature requests and bug reports welcome!
11
star
91

pulumi-query-kubernetes

A relational TypeScript SDK for querying Kubernetes resources in any cluster, either on-prem or in any cloud.
TypeScript
11
star
92

pulumi-newrelic

An New Relic Pulumi resource package, providing multi-language access to New Relic
Java
10
star
93

pulumi-nomad

Go
10
star
94

tf12-vs-pulumi

A collection of HCL2 examples, rewritten to Pulumi
10
star
95

introduction-to-pulumi

An interactive workshop to get started with Pulumi
Dockerfile
10
star
96

travisqueue

Sequence Travis builds per branch
Go
9
star
97

pulumi-tls

A Pulumi provider for TLS resource management
Java
9
star
98

pulumi-aws-static-website

TypeScript
9
star
99

tutorial-pulumi-fundamentals

JavaScript
9
star
100

pulumi-aws-apigateway

TypeScript
9
star