Portainer simplifies container management in Kubernetes by providing a user-friendly graphical interface. Without Portainer, managing containers often involves complex command-line tools. Portainer offers a visual alternative, allowing you to:
- View and manage running containers, including starting, stopping, restarting, and scaling them.
- Inspect container logs and access container shells.
- Manage container images, enabling effortless uploads, downloads, and deletions.
- Create and manage Kubernetes networks and volumes.
- Gain insights into your container environment through resource usage statistics.
Portainer essentially acts as a central hub for overseeing and interacting with your containerized applications within Kubernetes.
This blog post guides you through deploying Portainer, a popular container management tool, within your Kubernetes environment. We’ll explore two methods: using Helm charts and directly applying YAML manifests.
Prerequisites:
A functional Kubernetes cluster
- Helm v3.2 or later (for Helm deployment)
Choosing Your Deployment Method:
Helm offers a more streamlined approach, while manifests provide greater control. Let’s delve into each option for both Community and Enterprise Editions of Portainer.
Deployment with Helm
1. Install the Portainer Helm Repository
Copied!helm repo add portainer https://portainer.github.io/k8s/ helm repo update
2. Community Edition
- NodePort (local/remote cluster):
Copied!helm install --create-namespace -n portainer portainer portainer/portainer
- Cloud Provider Load Balancer:
Copied!helm install --create-namespace -n portainer portainer portainer/portainer \ --set service.type=LoadBalancer
- ClusterIP with Ingress:
Copied!helm install --create-namespace -n portainer portainer portainer/portainer \ --set service.type=ClusterIP
3. Enterprise Edition:
Similar to Community Edition, use the –set enterpriseEdition.enabled=true
flag alongside the service type specification in your Helm install command.
Deployment with Manifests:
- Access the relevant YAML manifest file based on your Edition and service type from Portainer’s GitHub repository
https://github.com/portainer/k8s/blob/master/deploy/helm/charts/portainer/templates/deployment.yaml
2. Apply the manifest using kubectl:
Copied!kubectl apply -f <path_to_your_manifest.yaml>
Persisting Data:
By default, both Helm charts and manifests create a persistent volume for Portainer’s data using your cluster’s default StorageClass. In multi-node environments with hostPath volumes (like microk8s), this might lead to data loss during pod rescheduling.
Workaround for Persistent Data Loss:
– Node Selector: Pin the Portainer pod to a specific node using a node selector. You can achieve this by:
- Editing your values.yaml file (Helm)
- Including –set nodeSelector.kubernetes.io/hostname= during Helm install
- Patching the deployment (manifest deployment) with a one-liner provided in the reference material.
Conclusion
This post equips you to deploy Portainer in your Kubernetes environment using either Helm or manifests. Remember to choose the method that best suits your comfort level and project requirements. For detailed instructions and advanced customization options, refer to the Portainer Helm chart README.
Leave a Reply