This guide is a work in progress. I will continue to update based on comments and questions from the community. Thanks for reading!
The Drone Kubernetes Runner takes a .drone.yml configuration and translates it into Kubernetes native pods, secrets, and services. So what does this mean if you are already running Drone on Kubernetes today? It means no more build agents. No more mounting the host machine Docker socket or running Docker in Docker. If you are into buzzwords, it means Drone is now Kubernetes Native.
The goal of this thread is to help you get up and running with the Drone development tools, so that you can test and contribute to the Drone Kubernetes Runner. If you want to contribute, you should use the command-line tools described below for testing. Compiling the full Drone server for testing purposes is not necessary, and quite frankly, will only make your life more difficult.
Source Code
The Drone Kubernetes Runner can be found here. You can clone the repository to your gopath and build using the instructions found here. The Kubernetes implementation can be found in this package. If you want to contribute to the Kubernetes Runner, this package (including any subdirectories) is the only code you should need to edit.
Creating a Pipeline
The Kubernetes Runner takes a yaml configuration file as input. The configuration file should define one or more pipelines of type Kubernetes.
Here is an example yaml:
kind: pipeline
type: kubernetes
name: default
clone:
disable: true
steps:
- name: greeting
image: alpine
commands:
- echo hello
- echo world
Executing the Pipeline
In the previous section we created a simple Kubernetes pipeline configuration file. Now we can use the drone-runner-kube
tool to execute the Pipeline. Install the drone-runner-kube binary to get started.
$ git clone https://github.com/drone-runners/drone-runner-kube
$ cd drone-runner-kube
$ go install
Once the binary is installed, execute the Pipeline with the below command. Note that this command should be executed in the same directory where the .drone.yml is stored. For initial testing, we recommend using the sample yaml file defined in the previous section.
$ drone-runner-kube exec --kubeconfig=$HOME/.kube/config
Testing Volumes
Every Drone pipeline has a shared volume, called the workspace, where your code is cloned. This ensures all steps have access to your source code, as well as any files or artifacts that are created. You can test this capability with the following yaml (compile the yaml and run).
kind: pipeline
type: kubernetes
name: default
clone:
disable: true
steps:
- name: foo
image: alpine
commands:
- touch hello.txt
- name: bar
image: alpine
commands:
- ls hello.txt
Testing Services
If you define a services section in your yaml configuration it is launched in the same pod and is accessible on localhost. You can test this capability with the below yaml.
kind: pipeline
type: kubernetes
name: default
steps:
- name: test
image: redis
commands:
- sleep 5
- redis-cli -h localhost ping
services:
- name: redis
image: redis
Testing Secrets
Secrets are mapped to Kubernetes secrets. You can test this capability with the below yaml configuration file. Note that you need to pass your secrets to the yaml in the compile step:
drone-runner-kube exec \
--kubeconfig=$HOME/.kube/config \
--secrets=username:janecitize,password:correct-horse-battery-staple
kind: pipeline
type: kubernetes
name: default
clone:
disable: true
steps:
- name: test
image: alpine
environment:
PASSWORD:
from_secret: password
USERNAME:
from_secret: username
commands:
- env
Debugging
You can use kubectl and the Kubernetes dashboard to debug a running pipeline. We also provide a simple utility that converts the configuration file to an approximate Kubernetes manifest. This can be useful when you want a better understanding of how Drone is creating Kubernetes resources. Please note It is NOT a usable manifest and is for debugging purposes only.
drone-runner-kube compile --spec
Issues and Bugs
You will notice the repository issue tracker is disabled. You should create topics for support, issues, ideas and general development in this discourse forum.
Please refrain from creating issues for this project in the core drone/drone repository. Issues created in the core Drone repository that are not directly related to the code in that repository will be closed.
How Can I Help?
I am glad you asked. This is just an initial implementation and there is plenty of room for improvement. If you have any questions you can post in this thread, create a new topic, or join our chatroom.