2023-06-16 14:10:53 -07:00
|
|
|
---
|
|
|
|
title_tag: Review the New Project | Kubernetes
|
|
|
|
meta_desc: This page provides an overview on how to review a new Kubernetes project.
|
|
|
|
title: Review project
|
|
|
|
h1: "Pulumi & Kubernetes: Review project"
|
|
|
|
weight: 4
|
|
|
|
menu:
|
|
|
|
clouds:
|
|
|
|
parent: kubernetes-get-started
|
|
|
|
identifier: kubernetes-review-project-get-started
|
|
|
|
|
|
|
|
aliases:
|
|
|
|
- /docs/quickstart/kubernetes/review-project/
|
|
|
|
- /docs/get-started/kubernetes/review-project/
|
|
|
|
---
|
|
|
|
|
|
|
|
Let's review some of the generated project files:
|
|
|
|
|
|
|
|
{{% choosable language "javascript,typescript,python,go,csharp,java" %}}
|
|
|
|
|
|
|
|
- `Pulumi.yaml` defines the [project](/docs/concepts/projects/).
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
|
|
|
{{% choosable language yaml %}}
|
|
|
|
|
|
|
|
- `Pulumi.yaml` defines both the [project](/docs/concepts/projects/) and the program that manages your stack resources.
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
|
|
|
- `Pulumi.dev.yaml` contains [configuration](/docs/concepts/config/) values for the [stack](/docs/concepts/stack/) we initialized.
|
|
|
|
|
|
|
|
{{% choosable language java %}}
|
|
|
|
|
|
|
|
- `src/main/java/myproject` defines the project's Java package root.
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
|
|
|
{{% choosable language "javascript,typescript,python,go,csharp,java" %}}
|
|
|
|
|
|
|
|
<!-- The wrapping spans are infortunately necessary here; without them, the renderer gets confused and generates invalid markup. -->
|
|
|
|
- <span>{{< langfile >}}</span> is the Pulumi program that defines your stack resources.
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
|
|
|
Let's examine {{< langfile >}}.
|
|
|
|
|
|
|
|
{{< chooser language "javascript,typescript,python,go,csharp,java,yaml" / >}}
|
|
|
|
|
|
|
|
{{% choosable language javascript %}}
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
"use strict";
|
|
|
|
const k8s = require("@pulumi/kubernetes");
|
|
|
|
|
|
|
|
const appLabels = { app: "nginx" };
|
|
|
|
const deployment = new k8s.apps.v1.Deployment("nginx", {
|
|
|
|
spec: {
|
|
|
|
selector: { matchLabels: appLabels },
|
|
|
|
replicas: 1,
|
|
|
|
template: {
|
|
|
|
metadata: { labels: appLabels },
|
|
|
|
spec: { containers: [{ name: "nginx", image: "nginx" }] }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
exports.name = deployment.metadata.name;
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
{{% choosable language typescript %}}
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
import * as k8s from "@pulumi/kubernetes";
|
|
|
|
|
|
|
|
const appLabels = { app: "nginx" };
|
|
|
|
const deployment = new k8s.apps.v1.Deployment("nginx", {
|
|
|
|
spec: {
|
|
|
|
selector: { matchLabels: appLabels },
|
|
|
|
replicas: 1,
|
|
|
|
template: {
|
|
|
|
metadata: { labels: appLabels },
|
|
|
|
spec: { containers: [{ name: "nginx", image: "nginx" }] }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
export const name = deployment.metadata.name;
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
{{% choosable language python %}}
|
|
|
|
|
|
|
|
```python
|
|
|
|
"""A Kubernetes Python Pulumi program"""
|
|
|
|
|
|
|
|
import pulumi
|
|
|
|
from pulumi_kubernetes.apps.v1 import Deployment, DeploymentSpecArgs
|
|
|
|
from pulumi_kubernetes.meta.v1 import LabelSelectorArgs, ObjectMetaArgs
|
|
|
|
from pulumi_kubernetes.core.v1 import ContainerArgs, PodSpecArgs, PodTemplateSpecArgs
|
|
|
|
|
|
|
|
app_labels = { "app": "nginx" }
|
|
|
|
|
|
|
|
deployment = Deployment(
|
|
|
|
"nginx",
|
|
|
|
spec=DeploymentSpecArgs(
|
|
|
|
selector=LabelSelectorArgs(match_labels=app_labels),
|
|
|
|
replicas=1,
|
|
|
|
template=PodTemplateSpecArgs(
|
|
|
|
metadata=ObjectMetaArgs(labels=app_labels),
|
|
|
|
spec=PodSpecArgs(containers=[ContainerArgs(name="nginx", image="nginx")])
|
|
|
|
),
|
|
|
|
))
|
|
|
|
|
|
|
|
pulumi.export("name", deployment.metadata["name"])
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
{{% choosable language go %}}
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-09-11 18:35:35 -07:00
|
|
|
appsv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apps/v1"
|
|
|
|
corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1"
|
|
|
|
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1"
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
|
2023-06-16 14:10:53 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2023-09-11 18:35:35 -07:00
|
|
|
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.Name())
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
2023-06-16 14:10:53 -07:00
|
|
|
}
|
2023-09-11 18:35:35 -07:00
|
|
|
|
2023-06-16 14:10:53 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
{{% choosable language csharp %}}
|
|
|
|
|
|
|
|
```csharp
|
|
|
|
using Pulumi;
|
|
|
|
using Pulumi.Kubernetes.Types.Inputs.Core.V1;
|
|
|
|
using Pulumi.Kubernetes.Types.Inputs.Apps.V1;
|
|
|
|
using Pulumi.Kubernetes.Types.Inputs.Meta.V1;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
return await Deployment.RunAsync(() =>
|
|
|
|
{
|
|
|
|
var appLabels = new InputMap<string>
|
|
|
|
{
|
|
|
|
{ "app", "nginx" }
|
|
|
|
};
|
|
|
|
|
|
|
|
var deployment = new Pulumi.Kubernetes.Apps.V1.Deployment("nginx", new DeploymentArgs
|
|
|
|
{
|
|
|
|
Spec = new DeploymentSpecArgs
|
|
|
|
{
|
|
|
|
Selector = new LabelSelectorArgs
|
|
|
|
{
|
|
|
|
MatchLabels = appLabels
|
|
|
|
},
|
|
|
|
Replicas = 1,
|
|
|
|
Template = new PodTemplateSpecArgs
|
|
|
|
{
|
|
|
|
Metadata = new ObjectMetaArgs
|
|
|
|
{
|
|
|
|
Labels = appLabels
|
|
|
|
},
|
|
|
|
Spec = new PodSpecArgs
|
|
|
|
{
|
|
|
|
Containers =
|
|
|
|
{
|
|
|
|
new ContainerArgs
|
|
|
|
{
|
|
|
|
Name = "nginx",
|
|
|
|
Image = "nginx",
|
|
|
|
Ports =
|
|
|
|
{
|
|
|
|
new ContainerPortArgs
|
|
|
|
{
|
|
|
|
ContainerPortValue = 80
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// export the deployment name
|
|
|
|
return new Dictionary<string, object?>
|
|
|
|
{
|
|
|
|
["name"] = deployment.Metadata.Apply(m => m.Name)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
|
|
|
{{% choosable language java %}}
|
|
|
|
|
|
|
|
```java
|
|
|
|
package myproject;
|
|
|
|
|
|
|
|
import com.pulumi.Pulumi;
|
|
|
|
import com.pulumi.kubernetes.apps_v1.Deployment;
|
|
|
|
import com.pulumi.kubernetes.apps_v1.DeploymentArgs;
|
|
|
|
import com.pulumi.kubernetes.apps_v1.inputs.DeploymentSpecArgs;
|
|
|
|
import com.pulumi.kubernetes.core_v1.inputs.ContainerArgs;
|
|
|
|
import com.pulumi.kubernetes.core_v1.inputs.ContainerPortArgs;
|
|
|
|
import com.pulumi.kubernetes.core_v1.inputs.PodSpecArgs;
|
|
|
|
import com.pulumi.kubernetes.core_v1.inputs.PodTemplateSpecArgs;
|
|
|
|
import com.pulumi.kubernetes.meta_v1.inputs.LabelSelectorArgs;
|
|
|
|
import com.pulumi.kubernetes.meta_v1.inputs.ObjectMetaArgs;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
public class App {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
Pulumi.run(ctx -> {
|
|
|
|
var labels = Map.of("app", "nginx");
|
|
|
|
|
|
|
|
var deployment = new Deployment("nginx", DeploymentArgs.builder()
|
|
|
|
.spec(DeploymentSpecArgs.builder()
|
|
|
|
.selector(LabelSelectorArgs.builder()
|
|
|
|
.matchLabels(labels)
|
|
|
|
.build())
|
|
|
|
.replicas(1)
|
|
|
|
.template(PodTemplateSpecArgs.builder()
|
|
|
|
.metadata(ObjectMetaArgs.builder()
|
|
|
|
.labels(labels)
|
|
|
|
.build())
|
|
|
|
.spec(PodSpecArgs.builder()
|
|
|
|
.containers(ContainerArgs.builder()
|
|
|
|
.name("nginx")
|
|
|
|
.image("nginx")
|
|
|
|
.ports(ContainerPortArgs.builder()
|
|
|
|
.containerPort(80)
|
|
|
|
.build())
|
|
|
|
.build())
|
|
|
|
.build())
|
|
|
|
.build())
|
|
|
|
|
|
|
|
.build())
|
|
|
|
.build());
|
|
|
|
|
|
|
|
var name = deployment.metadata()
|
|
|
|
.applyValue(m -> m.orElseThrow().name().orElse(""));
|
|
|
|
|
|
|
|
ctx.export("name", name);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
|
|
|
{{% choosable language yaml %}}
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
name: quickstart
|
|
|
|
runtime: yaml
|
|
|
|
description: A minimal Kubernetes Pulumi YAML program
|
|
|
|
|
|
|
|
variables:
|
|
|
|
appLabels:
|
|
|
|
app: nginx
|
|
|
|
|
|
|
|
resources:
|
|
|
|
deployment:
|
|
|
|
name: nginx
|
|
|
|
type: kubernetes:apps/v1:Deployment
|
|
|
|
properties:
|
|
|
|
spec:
|
|
|
|
selector:
|
|
|
|
matchLabels: ${appLabels}
|
|
|
|
replicas: 1
|
|
|
|
template:
|
|
|
|
metadata:
|
|
|
|
labels: ${appLabels}
|
|
|
|
spec:
|
|
|
|
containers:
|
|
|
|
- name: nginx
|
|
|
|
image: nginx
|
|
|
|
|
|
|
|
outputs:
|
|
|
|
name: ${deployment.metadata.name}
|
|
|
|
```
|
|
|
|
|
|
|
|
{{% /choosable %}}
|
|
|
|
|
|
|
|
This Pulumi program creates an NGINX deployment and exports the name of the deployment.
|
|
|
|
|
|
|
|
Next, we'll deploy the stack.
|
|
|
|
|
|
|
|
{{< get-started-stepper >}}
|