Setup Kubernetes cluster and deploy drone on AWS — Part II

Sam Wang
honestbee-tw-engineering
4 min readDec 21, 2018

In the previous Part I article, we already introduced how to set up a Kubernetes cluster on AWS, now, it’s time to deploy Drone service into it.

Why Drone?

People may ask why not using Jenkins to build the CI/CD process, the reason why we choose Drone is that it can use the container concept, and everything can be a container (except running Xcode UI testing). If you are not familiar with what is docker, can refer here. Jenkins requires difficult project settings and hard to extend the components if not having any Java developer in your team, that’s why we prefer using Drone to be our CI/CD tool.

Before docker announced, we usually need to establish multiple different services and deploy them one by one, the management cost also very high and the learning curve is steep, with docker and docker-compose, we can draw a map between services easily and deploy them in a few simple steps, team can be more focusing on writing business logic instead of stuck on DevOps.

Also, with docker-hub, it makes easier to get the open sourced contributed images to use. For example, if I want to deploy a Redis image to the cluster, I can just write:

redis:alpine is actually helping you to pull the Redis image from docker hub repository

Setup deployment.yml file

Having deployment.yml means you can use kubectl to create pods on the cluster, Drone’s architecture requires one server and multiple agents, we need to set up these within the development.yml to have deployment controllers.

Isolating pods under a namespace

When we set up namespace on Kubernetes cluster, the benefit is to isolate the pods under this namespace and will not be affected by other areas, also it can be easier to view and maintain the relevant deployment.

You can use kubectl create -f namespace.yml to generate the namespace.

Or, you can type in the console as well kubectl create namespace drone , then check if the namespace is created, after namespace created, we will set all the deployment under namespace: drone

The secret key to communicate between drone server and agent

In order to communicate between drone server and agent, we will need to generate a secret key

echo -n 'your key here' | base64

kubectl create -f secret.yml

Setup config map

Before writing deployment, it will be better if we can separate the config map file into a standalone yaml for a clear view.

Noted on the github settings, since our drone will connect with github for any push, pull request build, we have to create an OAuth app under developer settings first.

Set the Homepage URL to your host, and fulfill the Authorization callback URL with http(s)://host/authorize , after save, you should see Client ID & Client Secret, copy those to your config map yaml file.

The Deployment

Below are the complete deployment files, please aware that under volumes node we need to setup the AWS EBS volumeID, you can create a volume using aws command line tool.

aws ec2 create-volume --availability-zone=ap-southeast-1a --size=10 --volume-type=gp2

After executing, you can search forvol-xxxxx in your console, copy and paste into the development yaml volumeID.

Service definition

The service definition yaml described how AWS will set up the loading balancer and the annotations can set the ssl certificate id.

Final step

After all these yaml files, now it’s time to deploy the drone service onto AWS Kubernetes cluster.

$ kubectl create -f drone-namespace.yaml
$ kubectl create -f drone-secret.yaml
$ kubectl create -f drone-configmap.yaml
$ kubectl create -f drone-server-deployment.yaml
$ kubectl create -f drone-server-service.yaml
$ kubectl create -f drone-agent-deployment.yaml

You can check if the service is up kubectl --namespace=drone get service -o wide

And you can even check your pods has been created successfully.

Wanna Rollback?

Since we deploy the service under drone namespace, so the deletion is really easy by using kubectl delete -f drone-namespace.yaml

References

https://github.com/appleboy/drone-on-kubernetes/blob/master/aws/README.md

--

--