Drone services allow you to run a service container and will be available for the duration of your build, which is great if you want a ephemeral service to test your applications against.
Today we will experiment with services on drone and will deploy a k3s (a kubernetes distribution built by rancher) cluster as a drone service and interact with our cluster using kubectl.
I will be using multiple pipelines, where we will first deploy our “dev cluster”, when it’s up, we will use kubectl to interact with the cluster, once that is done, we will deploy our “staging cluster” and do the same.
This is very basic and we are not doing anything special, but this is a starting point and you can do pretty much whatever you want.
What is Drone
If you are not aware of Drone, Drone is a container-native continious deliver platform built on Go and you can check them out here: github.com/drone
Setup Gitea and Drone
If you don’t have the stack setup, have a look at this post where I go into detail on how to get that setup.
Create your Git Repo
Go ahead and create a git repo, you can name it anything, then it should look something like this:
Create a drone configuration, .drone.yml
my pipeline will look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
In this pipeline you can see that the staging pipeline depends on dev, so dev pipeline will start by creating the k3s service container, once its up I am using a step just to sleep for 30 seconds to allow it to boot.
Then I have defined a volume that will be persistent during the build time, which we will use to dump our kubeconfig file and update the hostname of our kubernetes endpoint. Once that is done our last step will set that file to the environment and use kubectl to interact with kubernetes.
Once our dev pipeline has finished, our staging pipeline will start.
Activate the Repo in Drone
Head over to drone on port 80
and activate the newly created git repo (and make sure that you select “Trusted”) and you will see the activity feed being empty:
Commit a dummy file to git and you should see your pipeline being triggered:
Once your pipeline has finished and everything succeeded, you should see the output of your nodes in your kubernetes service container:
As I mentioned earlier, we are not doing anything special but service containers allows us to do some awesome things.
Thank you for reading. If you like my content, feel free to visit me at ruan.dev or follow me on twitter at @ruanbekker