Using kubernetes apps with argoproj.io
TypeScriptArgo CD is a declarative, GitOps continuous delivery tool for Kubernetes. Pulumi does not have direct integration with Argo CD, but it can be used in combination with Kubernetes resources to deploy applications. Pulumi can be used to define the necessary Kubernetes resources like Deployments, Services, and others in code, and then Argo CD can be used to manage the deployment of those resources to a Kubernetes cluster using a GitOps workflow.
Below is a Pulumi program written in TypeScript that demonstrates how you can define a Kubernetes
Deployment
andService
for an example application, which you could then manage with Argo CD. In this example, we define a simplenginx
deployment and service.We'll start by installing the required Pulumi packages. We need the
@pulumi/kubernetes
package to create Kubernetes resources and the@pulumi/pulumi
package for Pulumi's core functionalities.First, install the required packages by running:
npm install @pulumi/kubernetes @pulumi/pulumi
Here's the TypeScript program that defines the Kubernetes resources:
import * as k8s from "@pulumi/kubernetes"; // Create a Kubernetes Namespace const ns = new k8s.core.v1.Namespace("app-ns", { metadata: { name: "argo-app-namespace", }, }); // Define the Deployment for the nginx application const appLabels = { app: "nginx" }; const deployment = new k8s.apps.v1.Deployment("app-deployment", { metadata: { namespace: ns.metadata.name, labels: appLabels, }, spec: { replicas: 2, selector: { matchLabels: appLabels }, template: { metadata: { labels: appLabels }, spec: { containers: [{ name: "nginx", image: "nginx:1.14.2", ports: [{ name: "http", containerPort: 80 }], }], }, }, }, }); // Define the Service to expose the nginx application const service = new k8s.core.v1.Service("app-service", { metadata: { namespace: ns.metadata.name, labels: appLabels, }, spec: { type: "LoadBalancer", ports: [{ port: 80, targetPort: "http" }], selector: appLabels, }, }); // Export the Service name and endpoint export const serviceName = service.metadata.name; export const serviceEndpoint = service.status.apply(status => status.loadBalancer.ingress[0].ip || status.loadBalancer.ingress[0].hostname);
In this program:
- We create a new Kubernetes namespace called
argo-app-namespace
to logically separate our resources within the cluster. - We define a Deployment named
app-deployment
using thenginx:1.14.2
image and specify that we want2
replicas. - We create a
Service
resource namedapp-service
that exposes ournginx
deployment to the internet through aLoadBalancer
. This service maps port 80 of the LoadBalancer to port 80 of ournginx
container. - We export the service name and the endpoint of the LoadBalancer as stack outputs.
To use these resources with Argo CD, you would commit your Pulumi code to a Git repository and point Argo CD to this repository. Argo CD would then sync your desired state defined in the Git repository to your Kubernetes cluster.
Please note that this is a basic example meant for learning purposes, and in practice, you might have more complex configurations including readiness and liveness probes, volume mounts, environment variables, secrets, etc. This example also assumes that the Kubernetes cluster and Pulumi are set up and configured appropriately.
For more information on Pulumi's Kubernetes resources, you can visit the Kubernetes API Docs.
- We create a new Kubernetes namespace called