Git Product home page Git Product logo

drone-on-k8s's Introduction

Yours Kindly Drone

A small demo and setup to demonstrate on how to setup Drone with kind as your local Kubernetes Cluster.

For complete walk through and explanation checkout my blog

Required tools

All linux distributions adds envsubst via gettext package. On macOS it can be installed using Homebrew like brew install gettext.

Clone the Sources

git clone https://github.com/kameshsampath/drone-on-k8s && \
  cd "$(basename "$_" .git)"
export PROJECT_HOME="${PWD}"

Create Kubernetes Cluster

$PROJECT_HOME/bin/kind.sh

Deploy Gitea

helm repo add gitea-charts https://dl.gitea.io/charts/
helm repo update
helm upgrade \
  --install gitea gitea-charts/gitea \
  --values $PROJECT_HOME/helm_vars/gitea/values.yaml \
  --wait

Setup Environment

Gitea URL

export GITEA_DOMAIN="gitea-127.0.0.1.sslip.io"
export GITEA_URL="http://${GITEA_DOMAIN}:3000"

You can access Gitea now in your browser using open ${GITEA_URL}. Default credentials demo/demo@123.

Drone URL

The URL where Drone Server will be deployed,

export DRONE_SERVER_HOST="drone-127.0.0.1.sslip.io:8080"
export DRONE_SERVER_URL="http://${DRONE_SERVER_HOST}"

Deploy Drone

Configure Gitea

Configure Gitea for oAuth to be used by Drone and the demo repository that will be clone from GitHub,

$PROJECT_HOME/bin/gitea-config-darwin-arm64 \
  -g "${GITEA_URL}" \
  -dh "${DRONE_SERVER_URL}"

NOTE: Please use the right gitea-config binary that suits your environment. In the example above we use the macOS binary

Deploy Drone,

Create namespace to deploy drone

kubectl create ns drone

Add drone helm repo,

helm repo add drone https://charts.drone.io
helm repo update

Deploy drone server,

helm upgrade --install drone drone/drone \
  --values $PROJECT_HOME/helm_vars/drone/values.yaml \
  --namespace=drone \
  --post-renderer  $PROJECT_HOME/k8s/kustomize \
  --wait

Host Aliases

By default gitea-127.0.0.1.sslip.io:3000 resolves to 127.0.0.1:3000 on the drone server pod. As we require gitea-127.0.0.1.sslip.io:3000 to be resolved to the gitea-http service on the cluster we do helm post render to add host aliases to drone server deployments to resolve the gitea-127.0.0.1.sslip.io:3000 to the ClusterIP of the gitea-http service.You can check the ClusterIP of the gitea service using the command kubectl get svc gitea-http -n default -ojsonpath='{.spec.clusterIP}'

As we did with drone server to resolve gitea-127.0.0.1.sslip.ip, we also need to update gitea deployment for host aliases to resolve drone-127.0.0.1.sslip.io:8080 to resolve to drone service on the drone namespace.

This time we will use kubectl patch technique,

export DRONE_SERVICE_IP="$(kubectl get svc -n drone drone -ojsonpath='{.spec.clusterIP}')"
kubectl patch statefulset gitea -n default --patch "$(envsubst<$PROJECT_HOME/k8s/patch.json)" 

You can now open the Drone Server using the url ${DRONE_SERVER_URL}, follow the onscreen instructions complete the registration and activate the drone-quickstart repo.

alt

Deploy Drone Runner

We need to deploy drone-runner-kube that will be used to run the pipelines on Kubernetes server,

helm upgrade --install drone-runner-kube drone/drone-runner-kube \
  --namespace=drone \
  --values $PROJECT_HOME/helm_vars/drone-runner-kube/values.yaml \
  --wait

Clone the Quickstart

Clone the drone-quickstart locally from Gitea, navigate to folder of your choice and run the following command,

git clone http://gitea-127.0.0.1.sslip.io:3000/demo/drone-quickstart.git
cd drone-quickstart

If you try to make some changes to the code and push to the Gitea repo you will see the build failing as shown

Failed build

Why the build fails?

As we use kind as your Kubernetes cluster we need to update .drone.yml hostAliases to point to the gitea-http ClusterIP, otherwise the clone step of the pipeline will fail with gitea-127.0.0.1.sslip.io trying to connected local step pod container on port3000.

To get the ClusterIP of the gitea-http service run the following command,

kubectl get svc gitea-http -n default -ojsonpath='{.spec.clusterIP}'

Commit and push the code to Gitea to see the building getting triggered. This time build succeeds as shown,

successful build

NOTE: The default Gitea credentials is demo/demo@123

Please check the docs for more configuration options.

Clean up

 kind delete cluster --name=drone-demo

Build Gitea Config Binaries

The demo uses a util code to configure Gitea, you can build the code using the command

./build.sh

The command generates a binary in $PROJECT_HOME/bin for each OS/Arch combination. Use the one that suits your OS/Arch combo.

drone-on-k8s's People

Contributors

kameshsampath avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

rod5600

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.