# Manage Kubernetes with Rundeck

Kubernetes (opens new window) (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 Process Automation (opens new window).

# Kubernetes and Rundeck

Rundeck uses the Kubernetes workflow step plugin (opens new window) 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

  1. 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:
    $ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
    $ sudo install minikube-linux-amd64 /usr/local/bin/minikube
    Click here (opens new window) 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 (opens new window), you can launch minikube in the following way:
    minikube start --driver=virtualbox
  2. Kubectl to interact with minikube
    Kubectl is a command-line tool for interacting with minikube. Click here (opens new window) to learn how to install Kubectl
  3. K9s for cluster monitoring (optional)
    K9s is a tool focused on monitoring and interacting with the cluster. Click here (opens new window) to learn how to install K9s
  4. Rundeck

# Kubernetes Rundeck Plugin Prerequisites

  1. Python3
  2. Kubernetes pip module
    Can be installed with
    pip3 install kubernetes

# Installing the Kubernetes Plugin in Rundeck

  1. Go to the System Menu > Plugins > Upload plugin

  2. Put in the latest version .zip file full URL path here.

  3. Click on the "install" button.

# Kubernetes Model Source

To manage K8s pods as nodes, it's necessary to add the Kubernetes model source.

  1. Go to Project Settings > Edit Nodes

  2. Click on the “Add a new Node Source +" button.

  3. From the list select "Kubernetes / Pods / Resource model"
  4. Save


    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
  5. Create a file named deployment.yaml with the following content:
    apiVersion: apps/v1
    kind: Deployment
     name: nginx-deployment
       app: nginx
     replicas: 1
     	 app: nginx
          app: nginx
     	- name: nginx
       	  image: nginx:1.15.4
          - containerPort: 80
  6. Deploy the test deployment with the following command:
    kubectl apply -f ./deployment.yaml
  7. Check if the deployment is running with k9s (just run the k9s command).

  8. Go back to Rundeck and refresh the Rundeck model source

  9. 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:

  1. Create a new Job and give it a name.
  2. Select the first Kubernetes step: Kubernetes / Generic / Create.

  3. Go to the "YAML String" textbox and add the following YAML content.
    apiVersion: apps/v1
    kind: Deployment
       	   app: mysql
        - image: mysqapiVersion: apps/v1
    kind: Deployment
     name: mysql
       app: mysql
     	  app: mysql
      type: Recreate
          name: mysql
          - name: MYSQL_ROOT_PASSWORD
          value: password
  4. Save the job and run.

  5. Run k9s to see that the new deployment is available on the minikube cluster:

  6. 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.

  1. Create / Update / Delete / Check / Wait a Deployment
    These steps manage deployment resources. You can create, update or delete a deployment and check its status.
  2. Create / Update / Delete Services
    These steps manage services resources. You can create, update or delete a service.
  3. Create / Delete / Re-run Jobs
    These steps manage services resources. You can create or delete a Job.