During the section we'll install deploy
task, which deploys the resources on a specific namespace and does rollout restart.
The deploy task uses an image that contains kubectl
in order to apply the resources to the cluster. The task needs to run with sufficient privileges to be able to apply the resources.
Before starting make sure you have the following:
- Kubernetes: kubernetes cluster up and running.
- Tekton: tekton installed.
- Build Task: Build task installed and run at least once so that we have a compiled image on the local registry.
- tkn: A CLI for interacting with Tekton.
Apply deploy-task.yaml
resource:
❯ kubectl apply -f tekton/2.tasks/deploy-task.yaml
task.tekton.dev/deploy created
List the installed tasks:
❯ tkn task list
NAME DESCRIPTION AGE
build build & push app 1 hour ago
deploy deploy & restart app 6 seconds ago
To verify our deploy task we'll deploy our app on tekton-tutorial
namespace.
Let's start the deploy task with param namespace:tekton-tutorial
and the rest with default values:
❯ tkn task start deploy -p namespace=tekton-tutorial --showlog
? Choose the git resource to use for source: tekton-tutorial-git (https://github.com/harbur/tekton-tutorial#main)
TaskRun started: deploy-run-49hcs
Waiting for logs to be available...
[git-source-source-zvvkh] {"level":"info","ts":1611582761.8638577,"caller":"git/git.go:165","msg":"Successfully cloned https://github.com/harbur/tekton-tutorial @ 869979df85d6cacfb5ff6ef29cb3fdd1148c00f3 (grafted, HEAD, origin/main) in path /workspace/source"}
[git-source-source-zvvkh] {"level":"info","ts":1611582761.9101276,"caller":"git/git.go:203","msg":"Successfully initialized and updated submodules in path /workspace/source"}
[run-kubectl] deployment.apps/tekton-tutorial created
[run-kubectl] service/tekton-tutorial created
[rollout-deploy] deployment.apps/tekton-tutorial restarted
Check the resources on tekton-tutorial
namespace:
❯ kubectl get deploy,pod,svc -n tekton-tutorial
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/tekton-tutorial 1/1 1 1 3m19s
NAME READY STATUS RESTARTS AGE
pod/tekton-tutorial-f54d695df-gpcfm 1/1 Running 0 2m17s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/tekton-tutorial NodePort 10.102.111.124 <none> 8080:31616/TCP 3m19s
Open service on browser:
❯ minikube service tekton-tutorial -n tekton-tutorial
|-----------------|-----------------|-------------|----------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------------|-----------------|-------------|----------------------------|
| tekton-tutorial | tekton-tutorial | 8080 | http://192.168.64.64:31411 |
|-----------------|-----------------|-------------|----------------------------|
🎉 Opening service tekton-tutorial/tekton-tutorial in default browser...
To delete the app:
❯ kubectl delete -f k8s -n tekton-tutorial
deployment.apps "tekton-tutorial" deleted
service "tekton-tutorial" deleted
If you want to learn more about the steps involved in this section, here are some interesting references:
- Tekton Hub: buildah: Buildah task builds source into a container image and then pushes it to a container registry.
Once deploy task is installed, see the Install Build-and-Deploy Pipeline tutorial.
If you want to tear down the deploy task:
❯ kubectl delete -f tekton/2.tasks/deploy-task.yaml
task.tekton.dev "deploy" deleted