Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
import * as k8s from "@pulumi/kubernetes";
// Create a new provider
const myk8s = new k8s.Provider("myk8s", {});
// Create a new provider with dry run enabled.
const myk8s2 = new k8s.Provider("myk8s2", {
enableDryRun: true,
});
// Create a Pod using the custom provider
const nginxcontainer = new k8s.core.v1.Pod("nginx", {
spec: {
containers: [{
image: "nginx:1.7.9",
name: "nginx",
ports: [{ containerPort: 80 }],
}],
},
}, { provider: myk8s });
// TODO(levi): Uncomment once https://github.com/pulumi/pulumi-kubernetes/issues/792 is fixed.
// // Create a Pod using the custom provider
// './node-app' directory, and push it to the registry.
const customImage = "node-app";
const appImage = new docker.Image(customImage, {
imageName: pulumi.interpolate`${registry.loginServer}/${customImage}:v1.0.0`,
build: {
context: `./${customImage}`,
},
registry: {
server: registry.loginServer,
username: registry.adminUsername,
password: registry.adminPassword,
},
});
// Create a k8s provider.
const provider = new k8s.Provider("provider", {
kubeconfig: config.kubeconfig,
namespace: config.appsNamespaceName,
});
// Create a Deployment of the built container.
const appLabels = { app: customImage };
const appDeployment = new k8s.apps.v1.Deployment("app", {
spec: {
selector: { matchLabels: appLabels },
replicas: 1,
template: {
metadata: { labels: appLabels },
spec: {
containers: [{
name: customImage,
image: appImage.imageName,
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
const config = new pulumi.Config();
const infrastructureStackName = config.require("infrastructureStackName");
const infrastructureStack = new pulumi.StackReference(infrastructureStackName);
export const k8sProvider = new k8s.Provider(`${infrastructureStackName}`, {
kubeconfig: infrastructureStack.getOutput("kubeconfig"),
});
auth-provider:
config:
cmd-args: config config-helper --format=json
cmd-path: gcloud
expiry-key: '{.credential.token_expiry}'
token-key: '{.credential.access_token}'
name: gcp
`;
});
// Export the cluster details.
export const kubeconfig = k8sConfig;
export const clusterName = cluster.name;
// Expose a k8s provider instance of the cluster.
const provider = new k8s.Provider(`${name}-gke`, { kubeconfig: k8sConfig });
// Create Kubernetes namespaces.
const clusterSvcsNamespace = new k8s.core.v1.Namespace("cluster-svcs", undefined, {
provider: provider,
});
export const clusterSvcsNamespaceName = clusterSvcsNamespace.metadata.name;
const appSvcsNamespace = new k8s.core.v1.Namespace("app-svcs", undefined, { provider: provider });
export const appSvcsNamespaceName = appSvcsNamespace.metadata.name;
const appsNamespace = new k8s.core.v1.Namespace("apps", undefined, { provider: provider });
export const appsNamespaceName = appsNamespace.metadata.name;
const nginxNs = new k8s.core.v1.Namespace("ingress-nginx", {metadata: {name: "ingress-nginx"}}, { provider: provider});
// Create a resource quota in the apps namespace.
import * as awsx from "@pulumi/awsx";
import * as k8s from "@pulumi/kubernetes";
import * as kx from "@pulumi/kubernetesx";
import { config } from "./config";
// Create a repository.
const repo = new awsx.ecr.Repository("my-repo");
// Build a Docker image from a local Dockerfile context in the
// './node-app' directory, and push it to the registry.
const customImage = "node-app";
const appImage = repo.buildAndPushImage(`./${customImage}`);
// Create a k8s provider.
const provider = new k8s.Provider("provider", {
kubeconfig: config.kubeconfig,
namespace: config.appsNamespaceName,
});
// Create a Deployment of the built container.
const appLabels = { app: customImage };
const appDeployment = new k8s.apps.v1.Deployment("app", {
spec: {
selector: { matchLabels: appLabels },
replicas: 1,
template: {
metadata: { labels: appLabels },
spec: {
containers: [{
name: customImage,
image: appImage,
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
import * as k8s from "@pulumi/kubernetes";
import * as kx from "@pulumi/kubernetesx";
import { config } from "./config";
const provider = new k8s.Provider("provider", {
kubeconfig: config.kubeconfig,
namespace: config.appsNamespaceName,
});
// Create a Secret with the database credentials.
const databaseSecret = new k8s.core.v1.Secret("db-secret", {
stringData: {
"database-username": config.databaseUsername,
"database-password": config.databasePassword,
}
}, { provider: provider });
// Create a Deployment that uses the database credentials as environment variables.
const appName = "nginx";
const appLabels = { app: appName };
const nginx = new k8s.apps.v1.Deployment(appName, {
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
import { config } from "./config";
const name = pulumi.getProject();
// A k8s provider instance of the cluster.
const provider = new k8s.Provider(`${name}-aks`, {
kubeconfig: config.kubeconfig,
});
// Boot up nodejs Helm chart example using the MongoDB instance of CosmosDB from App Services.
const node = new k8s.helm.v2.Chart(
"node",
{
repo: "bitnami",
chart: "node",
version: "4.0.1",
values: {
serviceType: "LoadBalancer",
mongodb: { install: false },
externaldb: { ssl: true, secretName: "mongo-secrets" },
},
},
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
let pulumiConfig = new pulumi.Config();
// Existing Pulumi stack reference in the format:
// // e.g. "myUser/myProject/dev"
const clusterStackRef = new pulumi.StackReference(pulumiConfig.require("clusterStackRef"));
// Get the kubeconfig from the cluster stack output.
const kubeconfig = clusterStackRef.getOutput("kubeconfig").apply(JSON.stringify);
// Create the k8s provider with the kubeconfig.
const provider = new k8s.Provider("k8sProvider", {kubeconfig});
const ns = new k8s.core.v1.Namespace("app-ns", {
metadata: { name: "joe-duffy" },
}, {provider});
const appLabels = { app: "iac-workshop" };
const deployment = new k8s.apps.v1.Deployment("app-dep", {
metadata: { namespace: ns.metadata.name },
spec: {
selector: { matchLabels: appLabels },
replicas: 1,
template: {
metadata: { labels: appLabels },
spec: {
containers: [{
name: "iac-workshop",
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
let pulumiConfig = new pulumi.Config();
// Existing Pulumi stack reference in the format:
// // e.g. "myUser/myProject/dev"
const clusterStackRef = new pulumi.StackReference(pulumiConfig.require("clusterStackRef"));
// Get the kubeconfig from the cluster stack output.
const kubeconfig = clusterStackRef.getOutput("kubeconfig").apply(JSON.stringify);
// Create the k8s provider with the kubeconfig.
const provider = new k8s.Provider("k8sProvider", {kubeconfig});
const ns = new k8s.core.v1.Namespace("app-ns", {
metadata: { name: "joe-duffy" },
}, {provider});
desiredCapacity: args.desiredCapacity,
amiId: args.nodeAmiId,
version: args.version,
instanceProfile: core.instanceProfile,
}, this, core.provider);
this.nodeSecurityGroup = this.defaultNodeGroup.nodeSecurityGroup;
configDeps.push(this.defaultNodeGroup.cfnStack.id);
}
// Export the cluster's kubeconfig with a dependency upon the cluster's autoscaling group. This will help
// ensure that the cluster's consumers do not attempt to use the cluster until its workers are attached.
this.kubeconfig = pulumi.all(configDeps).apply(([kubeconfig]) => kubeconfig);
// Export a k8s provider with the above kubeconfig. Note that we do not export the provider we created earlier
// in order to help ensure that worker nodes are available before the provider can be used.
this.provider = new k8s.Provider(`${name}-provider`, {
kubeconfig: this.kubeconfig.apply(JSON.stringify),
}, { parent: this });
// If we need to deploy the Kubernetes dashboard, do so now.
if (args.deployDashboard === undefined || args.deployDashboard) {
createDashboard(name, {}, this, this.provider);
}
this.registerOutputs({ kubeconfig: this.kubeconfig });
}