Skip to content

Commit

Permalink
Add Kubectl sample
Browse files Browse the repository at this point in the history
Use a image with `kubectl` installed, we can setup `step` of `task` in tekton to create arbitrary rsource of kubernates.
  • Loading branch information
vincent-pli committed Apr 15, 2020
1 parent 058bab1 commit d0db9ea
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
51 changes: 51 additions & 0 deletions kubectl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Kubectl

This Task deploys (or delete) a Kubernates resource (pod). It uses
[`kubectl`](https://kubernetes.io/zh/docs/reference/kubectl/kubectl/) for that.

## Install the Task

```
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/kubectl/kubectl-deploy.yaml
```

## Install ClusterRolebinding

```
kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/kubectl/clusterrolebinding.yaml
```

## Inputs

### Parameters

* **manifest:**: The content of the resource to deploy

## Usage

This TaskRun runs the Task to deploy the given Kubernetes resource.

```
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: kubectl-deploy-pod
spec:
taskRef:
name: kubectl-deploy-pod
inputs:
params:
- name: manifest
value: |
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: docker
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']
```
12 changes: 12 additions & 0 deletions kubectl/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: default-admin
subjects:
- kind: ServiceAccount
name: default
namespace: default
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
18 changes: 18 additions & 0 deletions kubectl/kubectl-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: kubectl-deploy-pod
namespace: default
spec:
params:
- name: manifest
description: Content of the resource to deploy
- name: image
default: gcr.io/cloud-builders/kubectl # it is huge
description: Kubectl wrapper image
steps:
- name: kubeconfig
image: $(inputs.params.image)
script: |
echo "$(inputs.params.manifest)" > /tmp/resource.yaml
kubectl create -f /tmp/resource.yaml
21 changes: 21 additions & 0 deletions kubectl/taskrun.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: kubectl-deploy-pod
spec:
taskRef:
name: kubectl-deploy-pod
params:
- name: manifest
value: |
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp-container
image: docker
command: ['sh', '-c', 'echo Hello Kubernetes! && sleep 3600']

0 comments on commit d0db9ea

Please sign in to comment.