https://github.com/pgroenbaek/drone-kubectl-helm3
DroneCI plugin with kubectl and helm3.
https://github.com/pgroenbaek/drone-kubectl-helm3
drone-ci drone-plugin helm kubectl kubernetes
Last synced: 2 months ago
JSON representation
DroneCI plugin with kubectl and helm3.
- Host: GitHub
- URL: https://github.com/pgroenbaek/drone-kubectl-helm3
- Owner: pgroenbaek
- License: gpl-3.0
- Created: 2024-11-22T15:52:42.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2025-03-07T19:13:57.000Z (2 months ago)
- Last Synced: 2025-03-07T20:24:54.153Z (2 months ago)
- Topics: drone-ci, drone-plugin, helm, kubectl, kubernetes
- Language: Shell
- Homepage:
- Size: 12 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# drone-kubectl-helm3
[](https://hub.docker.com/r/pgroenbaek/drone-kubectl-helm3/tags)
[](https://www.drone.io/)
[](https://helm.sh/)
[](https://kubernetes.io/docs/reference/kubectl/)
[](/LICENSE)This [Drone CI](https://drone.io/) plugin allows you to use `kubectl` and `helm` in pipelines without setting up kubectl authentication manually as pipeline commands.
## Usage
The following example shows how to configure a pipeline step to use the plugin via Docker Hub:
```yaml
kind: pipeline
name: check versionsteps:
- name: versions
image: pgroenbaek/drone-kubectl-helm3
settings:
kubernetes_user:
kubernetes_server:
kubernetes_cert:
from_secret: k8s_cert
kubernetes_token:
from_secret: k8s_token
commands:
- kubectl version
- helm version
```You need to define `k8s_cert` and `k8s_token` as pipeline secrets. You also need to specify the kubernetes service account name and server url.
Read the next section if you don't know how to get these.
## Getting the kubernetes cluster credentials
There is a slight variation in how to create the credentials depending on the kubernetes version.Kubernetes versions 1.23 and older will automatically create a token for you when creating the service account, while you manually need to create one in kubernetes versions 1.24 and newer.
### Kubernetes 1.24 and newer
First create a service account in the kubernetes cluster. This service account allows the pipeline to perform work on the cluster.
```bash
kubectl create serviceaccount
kubectl create clusterrolebinding --clusterrole=cluster-admin --serviceaccount=default:
```Create the kubernetes auth token:
```bash
kubectl create token -n default --duration=8760h
```**NOTE:** The token created with the above command will last for one year, change `8760h` if needed.
You can find your server url by using this command:
```bash
kubectl config view -o jsonpath='{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}'
```You can find the certificate by using this command:
```bash
kubectl get configmap -n kube-system kube-root-ca.crt -o jsonpath='{.data.ca\.crt}' | base64 -w 0
```### Kubernetes 1.23 and older
First create a service account in the kubernetes cluster. This service account allows the pipeline to perform work on the cluster.
```bash
kubectl create serviceaccount
kubectl create clusterrolebinding --clusterrole=cluster-admin --serviceaccount=default:
```You can find your server url by using this command:
```bash
kubectl config view -o jsonpath='{range .clusters[*]}{.name}{"\t"}{.cluster.server}{"\n"}{end}'
```If the service account name is `deploy`, you would now have a secret named `deploy-token-xxxx` (xxxx is some random characters).
You can find the token by using this command:
```bash
kubectl get secret deploy-token-xxxx -o jsonpath='{.data.token}' | base64 --decode && echo
```You can find the certificate by using this command:
```bash
kubectl get secret deploy-token-xxxx -o jsonpath='{.data.ca\.crt}' && echo
```## Using a private container registry
If you would rather use the plugin from a private container registry, clone this repository, then build and push the created docker image to your private registry:
```bash
docker login -u
docker build -t drone-kubectl-helm3 .
docker tag drone-kubectl-helm3 /drone-kubectl-helm3:
docker push /drone-kubectl-helm3:
```Replace the ``, `` and `` parameters with your values.
Now you can use the docker image you built as a drone plugin:
```yaml
kind: pipeline
name: check versionsteps:
- name: versions
image: /drone-kubectl-helm3:
settings:
kubernetes_user:
kubernetes_server:
kubernetes_cert:
from_secret: k8s_cert
kubernetes_token:
from_secret: k8s_token
commands:
- kubectl version
- helm versionimage_pull_secrets:
- docker_config_json
```Note the `image_pull_secrets` parameter at the bottom.
For Drone CI to know how to authenticate with your private container registry a secret named `docker_config_json` must be defined for the pipeline.
Add the following as a secret named `docker_config_json`:
```json
{"auths": {"": {"auth": ""}}}
```
Replace the `` and `` parameters with your values.## License
This drone plugin was created by Peter Grønbæk Andersen based on [drone-kubectl](https://github.com/sinlead/drone-kubectl) and is licensed under [GNU GPL v3](./LICENSE).