question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to export Kubernetes YAML

See original GitHub issue

Being able to export Kubernetes YAML will be important, especially for certain classes of users who may already have existing tools and practices for deployments. The challenge we have, and have always had due to the fact that evaluations can depend on output properties (the same reason we can’t produce plans ahead of time), but there are still things we can do to make this better. For instance:

  1. Show as much of the YAML as possible for a preview, even if there are “holes” in it.

  2. Emit the fully resolved YAML “as we go” so that it can be checkpointed in the usual way. For instance, folks practicing “GitOps”

In the first case, someone could always take the output and apply it with kubectl. In fact, if we had a mode that rejected holes, and emitted resources in the correct order based on DAG dependency order, then we could just step out of the way and it would still be an improvement over today’s practices.

Both of these seem imminently doable and something we should strongly consider.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:15
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

19reactions
steveseacommented, Jul 16, 2019

My use case: I’d like to use Pulumi to bootstrap my infrastructure (GCP, GKE, CloudSQL, PubSub, etc), and create some k8s secrets for credentials into the created cluster… But I don’t want to deploy my applications into the cluster through Pulumi. Rather, I might define Kubernetes Deployment & Service via Pulumi, then render that to YaML and have Argo CD manage synchronizing the pulumi-rendered YaML into the k8s cluster.

Argo has a plugin feature that seems like it could work: https://argoproj.github.io/argo-cd/user-guide/config-management-plugins/

5reactions
joeduffycommented, Dec 4, 2019

This isn’t a complete solution, however I do want to note that pulumi preview supports a --json option. As Levi says, there is a potential for missing values since they might not be known in advance due to dependencies, etc.; however, mixed with some jq magic, we can get close.

For instance, given this program:

import * as kx from "@pulumi/kubernetesx";
const pb = new kx.PodBuilder({
    containers: [{
        image: "nginx",
        ports: { http: 80 },
    }]
});
const dep = new kx.Deployment("nginx", {
    spec: pb.asDeploymentSpec({ replicas: 3 }),
});
const svc = dep.createService({
    type: kx.types.ServiceType.LoadBalancer,
});
export const url = svc.status.loadBalancer.ingress[0].hostname;

We can run this command:

$ pulumi preview -j | \
    jq '[ .steps[] | select(.newState.type | startswith("kubernetes:")) | .newState.outputs ]' | \
    yq r -

The output is the following YAML:

- apiVersion: apps/v1
  kind: Deployment
  metadata:
    annotations:
      pulumi.com/autonamed: "true"
    labels:
      app.kubernetes.io/managed-by: pulumi
    name: nginx-fx1tao6r
  spec:
    replicas: 3
    selector:
      matchLabels:
        app: nginx
    template:
      metadata:
        labels:
          app: nginx
      spec:
        containers:
        - env: []
          image: nginx
          name: nginx
          ports:
          - containerPort: 80
            name: http
          volumeMounts: []
        volumes: []
- apiVersion: v1
  kind: Service
  metadata:
    annotations:
      pulumi.com/autonamed: "true"
    labels:
      app.kubernetes.io/managed-by: pulumi
    name: nginx-f9vzqp9c
  spec:
    ports:
    - name: http
      port: 80
    selector:
      app: nginx
    type: LoadBalancer

Not 100% of what we’re after here, but very close …

Read more comments on GitHub >

github_iconTop Results From Across the Web

kubectl export yaml OR How to generate YAML for deployed ...
In this post, we are going to see how to get YAML of deployed Kubernetes resources(pvc, configmap, ingress, service, secret, deployment, ...
Read more >
How Do I Export YAML from Deployed Kubernetes Services?
Step 1: Start minikube Cluster · Step 2: View information regarding the current cluster · Step 3: Creating Single YAML for all services...
Read more >
Get YAML for deployed Kubernetes services? - Stack Overflow
To generate YAML for deployment you can run the imperative command. To genarate and export the deployment you can run the imperative command....
Read more >
Kubernetes: export a clean yaml manifest that can be re ...
It is easy to export the full manifest of an object from a Kubernetes cluster, but it will have extraneous accounting fields that...
Read more >
kubectl export YAML | Get YAML for deployed kubernetes ...
In this lab session on "How to export the YAML using kubectl?" we will focus on - Individual ya... Tagged with docker, kubernetes,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found