In this blog post, you will learn how to use Portainer to easily handle multi cluster management from a single instance of Portainer's easy Kubernetes GUI. This is accomplished by deploying an instance of the Portainer agent in every cluster you wish to manage and then connecting the central Portainer instance to the agents. We've also posted a 'how-to' video on this topic on our YouTube channel here.
For the purpose of this blog, the central instance of Portainer is running on a dedicated management instance using Docker,
Pre-reqs and assumptions:
- Run the commands as super-user (root) or with sudo;
- Use a modern Linux OS with snap support (not necessary for the deployment of the agent on Azure);
Deploy the centralized Portainer instance on Docker
Let's start by deploying a standalone Portainer instance. This can be done on a machine running on a local network, personal computer or laptop.
- On a terminal app of your preferences with docker installed (you can follow the official documentation here on how to install docker) run the commands below:
docker volume create portainer_data
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
- Once Portainer has been installed you can access the UI by opening a browser and typing the IP address of the machine where it has been deployed on port 9000, for example http://192.168.1.100:9000. You will land on Create the administrator user page:
- On the next screen make sure to select the Manage the local Docker environment option, click on Connect ...
- ...and you should land on the local endpoint where your standalone Portainer instance is running:
Deploy the Kubernetes NodePort agent on the first remote cluster
- Open your preferred terminal app;
- Login to the main node machine of your kubernetes cluster via ssh;
- Run the commands below as super-user or with sudo:
curl -L https://downloads.portainer.io/portainer-agent-k8s-nodeport.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml
kubectl get pods --namespace=portainer
–> this will show the state of the agent
- Open Portainer on your browser and select Home->Endpoints:
- Select Add endpoint:
- Select Portainer Agent:
- Fill the following variables on the form:
- Name: pick a name to identify your environment cluster, for example local kubernetes cluster
- Endpoint URL: {IP address:30778} where IP address is the ip of the machine where you installed the agent.
- If all goes well you should see a Endpoint created pop-up box and the Kubernetes features configuration page :
- For a kubernetes cluster running on-premise you can set the Enable features using metrics server and the microk8s-hostpath options
- Your Portainer home screen should show the new Endpoint:
Deploy the Docker Swarm agent on the second remote cluster
The Docker Swarm agent installation is straightforward and easy.
- Open your preferred terminal app;
- Login to the manager machine via ssh;
- Run the commands below as super-user or with sudo:
curl -L https://downloads.portainer.io/agent-stack.yml -o agent-stack.yml && docker stack deploy --compose-file=agent-stack.yml portainer-agent
docker service ls
–> this will show the state of the agent
- Repeat steps 4 through 7 from the Deploy the Kubernetes NodePort agent but making sure to use port 9001 instead of 30778 on the Endpoint URL
Deploy the Azure AKS Load Balancer agent on the third remote cluster
Installing the Portainer agent on Azure AKS can be 100% on the Azure Portal.
- Open Cloud Shell on your Azure Portal:
- Run the commands below:
az aks get-credentials --resource-group portainer-endpoint-demo --name portainerEndpointDemo
–> downloads the credentials to the .kube/config file so you can manage the kubernetes cluster with kubectl, make sure to replace the resource group and the cluster name accordinglycurl -L https://downloads.portainer.io/portainer-agent-k8s-lb.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml
kubectl get pods --namespace=portainer
–> this will show the state of the agent
- Once the agent is installed you can close the Cloud Shell box and go to:
- Kubernetes services:
- Select the cluster where the agent was deployed:
- Open the Services and ingresses option and you will see the public IP address deployed by the Portainer agent on the cluster:
- Kubernetes services:
- Repeat steps 4 through 7 from the Deploy the Kubernetes NodePort agent but making sure to use the public IP assigned by the Azure service with port 9001 on the Endpoint URL.
- The Kubernetes features configuration is slightly different than the one used for the on-premise kubernetes cluster:
- Enable the ingress controller. For Azure the name of the controller is nginx and type nginx
- Enable at least one Storage option:
- Explanation of the Azure Storage types can be found here.
Deploy the DigitalOcean Load Balancer agent on the fourth remote cluster
- For DigitalOcean the pre-req is that you have their doctl command line utility installed and authenticated. Please refer to the installation page for doctl here.
- The other pre-req is kubectl installed via the snap package manager. Make sure to install the same version of kubectl as the one on your hosted cluster.
- Open your preferred terminal app
curl -L https://downloads.portainer.io/portainer-agent-k8s-lb.yaml -o portainer-agent-k8s.yaml; kubectl apply -f portainer-agent-k8s.yaml
kubectl get pods --namespace=portainer
–> this will show the state of the agent
- Go to the Networking option on your DigitalOcean dashboard:
- Will should see a public IP address assigned via a Load Balancer to your cluster:
- Repeat steps 4 through 7 from the Deploy the Kubernetes NodePort agent but making sure to use port 9001 and the public IP assigned by Digital Ocean on the Endpoint URL
COMMENTS