How do I deploy multi-container applications with Portainer?
In this guide, we will deploy a multi-container application using Portainer on a Kubernetes cluster. Portainer is a lightweight management UI that allows you to easily manage your Docker environments. We will use Pulumi to define and deploy the necessary Kubernetes resources.
Key Points
- We will create a Kubernetes namespace for Portainer.
- We will deploy Portainer using a Kubernetes Deployment resource.
- We will expose Portainer using a Kubernetes Service resource.
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
// Create a namespace for Portainer
const namespace = new k8s.core.v1.Namespace("portainer-ns", {
metadata: {
name: "portainer",
},
});
// Define the Portainer deployment
const portainerDeployment = new k8s.apps.v1.Deployment("portainer-deployment", {
metadata: {
namespace: namespace.metadata.name,
name: "portainer",
},
spec: {
replicas: 1,
selector: {
matchLabels: {
app: "portainer",
},
},
template: {
metadata: {
labels: {
app: "portainer",
},
},
spec: {
containers: [
{
name: "portainer",
image: "portainer/portainer-ce:latest",
ports: [
{
containerPort: 9000,
},
],
volumeMounts: [
{
name: "data",
mountPath: "/data",
},
],
},
],
volumes: [
{
name: "data",
persistentVolumeClaim: {
claimName: "portainer-pvc",
},
},
],
},
},
},
});
// Define the PersistentVolumeClaim for Portainer data
const pvc = new k8s.core.v1.PersistentVolumeClaim("portainer-pvc", {
metadata: {
namespace: namespace.metadata.name,
name: "portainer-pvc",
},
spec: {
accessModes: ["ReadWriteOnce"],
resources: {
requests: {
storage: "10Gi",
},
},
},
});
// Expose Portainer using a Service
const portainerService = new k8s.core.v1.Service("portainer-service", {
metadata: {
namespace: namespace.metadata.name,
name: "portainer",
},
spec: {
type: "LoadBalancer",
ports: [
{
port: 9000,
targetPort: 9000,
},
],
selector: {
app: "portainer",
},
},
});
// Export the URL for accessing Portainer
export const portainerUrl = pulumi.interpolate`http://${portainerService.status.loadBalancer.ingress[0].ip}:9000`;
Summary
In this guide, we deployed a multi-container application using Portainer on a Kubernetes cluster with Pulumi. We created a Kubernetes namespace, a Deployment for Portainer, a PersistentVolumeClaim for storage, and a Service to expose Portainer. The portainerUrl
export provides the URL to access the Portainer UI.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.