Manage Kubernetes with Rundeck
Manage Kubernetes with Rundeck
Kubernetes (K8s) is an open-source platform for managing containerized services. It is used in many environments, but particularly as part of cloud-native applications where it is important to be able to scale up and down at will. The architecture makes scaling and recycling container based services easy.
Kubernetes services, support, and tools are widely available and very customizable and can be used in two different ways in the context of Rundeck. K8s can be used to automate the build and management of Rundeck as a container. For the purposes of this article, we’ll be focused on the more common way to use Kubernetes and Rundeck together, managing a complete Kubernetes cluster environment.
The article is written assuming use of Rundeck Community, our open-source offering, but can also be done using the commercial version, PagerDuty Runbook Automation.
Kubernetes and Rundeck
Rundeck uses the Kubernetes workflow step plugin to manage K8s. In this guide, we explain how to configure the plugin, how to manage pods as nodes, and how to use the workflow steps to interact with Kubernetes components.
Prerequisites for This Tutorial
- Minikube as a local Kubernetes cluster
Minikube is a local Kubernetes implementation and it’s an easy way to learn Kubernetes using any computer.
To install Minikube on Linux, download and copy the binary to/usr/local/bin/
path with the correct permissions:Click here to learn more about the minikube installation. Minikube can be configured using a specific driver (such as docker, VirtualBox, qemu, etc.). An easy way to get started is to run using Virtualbox on a local machine. After installing Virtualbox, you can launch minikube in the following way:$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 $ sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube start --driver=virtualbox
- Kubectl to interact with minikube
Kubectl is a command-line tool for interacting with minikube. Click here to learn how to install Kubectl - K9s for cluster monitoring (optional)
K9s is a tool focused on monitoring and interacting with the cluster. Click here to learn how to install K9s - Rundeck
Kubernetes Rundeck Plugin Prerequisites
- Python3
- Kubernetes pip module
Can be installed withpip3 install kubernetes
Installing the Kubernetes Plugin in Rundeck
- Go to the System Menu > Plugins > Upload plugin
- Put in the latest version .zip file full URL path here.
- Click on the "install" button.
Kubernetes Model Source
To manage K8s pods as nodes, it's necessary to add the Kubernetes model source.
- Go to Project Settings > Edit Nodes
- Click on the “Add a new Node Source +" button.
- From the list select "Kubernetes / Pods / Resource model"
- Save
Tips
By default and if authentication parameters are not set, the plugin will check the file
~/.kube/config
to get the authentication parameters.
Otherwise, you can set the following parameters:- Kubernetes Config File Path: a custom path for the Kubernetes config file
- Cluster URL: Kubernetes Cluster URL
- Kubernetes API Token: Token to connect to the Kubernetes API
- Verify SSL: Enable/disable the SSL verification
- SSL Certificate Path: SSL certificate path for SSL connections
- Kubernetes Config File Path: a custom path for the Kubernetes config file
- Create a file named
deployment.yaml
with the following content:apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.15.4 ports: - containerPort: 80
- Deploy the test deployment with the following command:
kubectl apply -f ./deployment.yaml
- Check if the deployment is running with k9s (just run the
k9s
command). - Go back to Rundeck and refresh the Rundeck model source
- Now go to the Commands section and select the Kubernetes pod in the node filter and put any command.
Kubernetes Workflow Steps
Next, we’ll simulate a simple deployment using the Kubernetes / Generic / Create
workflow step, carrying out a MySQL database deployment:
- Create a new Job and give it a name.
- Select the first Kubernetes step:
Kubernetes / Generic / Create
. - Go to the "YAML String" textbox and add the following YAML content.
apiVersion: apps/v1 kind: Deployment metadata: labels: app: mysql spec: containers: - image: mysqapiVersion: apps/v1 kind: Deployment metadata: name: mysql labels: app: mysql spec: selector: matchLabels: app: mysql strategy: type: Recreate template: l:5.6 name: mysql env: - name: MYSQL_ROOT_PASSWORD value: password
- Save the job and run.
- Run k9s to see that the new deployment is available on the minikube cluster:
- The new deployment is added to the nodes section. Now it's possible to dispatch commands against the pods or create jobs against them.
Other Available Workflow Steps
The following plugins allow you to deploy/un-deploy applications and run/re-run jobs on Kubernetes. For example, you can create a deployment, services, ingress, etc., and update or delete those Kubernetes resources.
- Create / Update / Delete / Check / Wait a Deployment
These steps manage Kubernetes Deployment resources. You can create, update or delete a deployment and check its status. - Create / Update / Delete Services
These steps manage Kubernetes Service resources. You can create, update or delete a service. - Create / Delete / Re-run Jobs
These steps manage Kubernetes Job resources. You can create or delete a Job.