提交 95611dfe 编写于 作者: J JJ Asghar 提交者: tekton-robot

Moving the tutorials over to the tekton namespace

- Moved over Brandow Walker's dashboard tutorial
- Created the basic pipeline tutorial
Signed-off-by: NJJ Asghar <jjasghar@gmail.com>
Co-authored-by: NBrandon Walker <bcwalker@ibm.com>
上级 85a5dcbf
# Additional resources
Now you have the core component of Tekton, Tekton Pipelines, installed on
your Kubernetes or OpenShift cluster with the Tekton CLI installed on katacoda.
If you would like to continue learning about Tekton, take a look at the following
topics:
* [Tekton Triggers](https://tekton.dev/docs/triggers)
* [Tekton Dashboard](https://tekton.dev/docs/dashboard)
{
"title": "Tekton Basic Pipeline",
"description": "Learn how to build a basic Tekton Pipeline!",
"difficulty": "Beginner",
"time": "30",
"details": {
"steps": [
{
"title": "Create a basic Task",
"text": "step1.md",
"code": "init.sh"
},
{
"title": "Create a second basic Task",
"text": "step2.md"
},
{
"title": "Create a Pipeline and PipelineRun",
"text": "step3.md"
}
],
"intro": {
"text": "intro.md"
},
"finish": {
"text": "finish.md"
},
"assets": {
"host01": [
{
"file": "*",
"target": "~/"
}
]
}
},
"environment": {
"uilayout": "terminal-iframe"
},
"backend": {
"imageid": "kubernetes",
"imageid": "kubernetes-cluster-running:1.18",
"port": "80"
}
}
# Wait for Katacoda to initialize
sleep 1
# Start Kubernetes
launch.sh
# Install Tekton Pipelines
kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.13.2/release.yaml
# If we ever decide to run latest :)
# kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
# Install the Tekton CLI
curl -LO https://github.com/tektoncd/cli/releases/download/v0.10.0/tkn_0.10.0_Linux_x86_64.tar.gz
sudo tar xvzf tkn_0.10.0_Linux_x86_64.tar.gz -C /usr/local/bin/ tkn
# Introduction to the Tekton Pipeline
In this tutorial, we will go through:
- Building a first and second task
- Building a pipeline
- Running a pipeline
- Checking the logs of the run
In this section, we will build the first task.
With Tekton, each operation in your CI/CD workflow becomes a Step, which is executed with a container image you specify. Steps are then organized in Tasks, which run as a Kubernetes pod in your cluster. You can further organize Tasks into Pipelines, which can control the order of execution of several Tasks.
To create a Task, create a Kubernetes object using the Tekton API with the kind Task. The following YAML file specifies a Task with one simple Step, which prints a Hello World! message using the official Ubuntu image:
```yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: hello
spec:
steps:
- name: hello
image: ubuntu
command:
- echo
args:
- "Hello World!"
```{{copy}}
Write the YAML above to a file named task-hello.yaml, and apply it to your Kubernetes cluster:
```bash
kubectl apply -f task-hello.yaml
```{{execute}}
To run this task with Tekton, you need to create a TaskRun, which is another Kubernetes object used to specify run time information for a Task.
To view this TaskRun object you can run the following Tekton CLI (tkn) command:
```bash
tkn task start hello --dry-run
```{{execute}}
After running the command above, the following TaskRun definition should be shown:
```yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
generateName: hello-run-
spec:
taskRef:
name: hello
```{{copy}}
To use the TaskRun above to start the hello Task, you can either use tkn or kubectl.
Start with tkn:
```bash
tkn task start hello
```{{execute}}
Start with kubectl:
```bash
# use tkn's --dry-run option to save the TaskRun to a file
tkn task start hello --dry-run > taskRun-hello.yaml
# create the TaskRun
kubectl create -f taskRun-hello.yaml
```{{execute}}
Tekton will now start running your Task. To see the logs of the last TaskRun, run the following tkn command:
```bash
tkn taskrun logs --last -f
```{{execute}}
It may take a few moments before your Task completes. When it executes, it should show the following output:
```console
[hello] Hello World!
```
In this section, we will build upon the first task we created and create
a second task and verify it. It may seem repeatitive, but this is just an
example. (after you're done just imagine what you could do!)
## Extending your first CI/CD Workflow with a second Task and a Pipeline
As you learned previously, with Tekton, each operation in your CI/CD workflow becomes a `Step`,
which is executed with a container image you specify. `Steps` are then
organized in `Tasks`, which run as a [Kubernetes pod](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/)
in your cluster. You can further organize `Tasks` into `Pipelines`, which
can control the order of execution of several `Tasks`.
To create a second `Task`, create a Kubernetes object using the Tekton API with
the kind `Task`. The following YAML file specifies a `Task` with one simple
`Step`, which prints a `Goodbye World!` message using
[the official Ubuntu image](https://hub.docker.com/_/ubuntu/):
```yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: goodbye
spec:
steps:
- name: goodbye
image: ubuntu
script: |
set -e
echo "Goodbye World!"
```{{copy}}
Write the YAML above to a file named `task-goodbye.yaml`, and apply it to your Kubernetes cluster:
```bash
kubectl apply -f task-goodbye.yaml
```{{execute}}
To run this task with Tekton, you need to create a `TaskRun`, which is
another Kubernetes object used to specify run time information for a `Task`.
To view this `TaskRun` object you can run the following Tekton CLI (`tkn`) command:
```bash
tkn task start goodbye --dry-run
```{{execute}}
After running the command above, the following `TaskRun` definition should be shown:
```yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
generateName: goodbye-run-
spec:
taskRef:
name: goodbye
```{{copy}}
To use the `TaskRun` above to start the `echo` `Task`, you can either use
`tkn` or `kubectl`.
Start with `tkn`:
```bash
tkn task start goodbye
```{{execute}}
Start with `kubectl`:
```bash
# use tkn's --dry-run option to save the TaskRun to a file
tkn task start goodbye --dry-run > taskRun-goodbye.yaml
# create the TaskRun
kubectl create -f taskRun-goodbye.yaml
```{{execute}}
Tekton will now start running your `Task`. To see the logs of the `TaskRun`, run
the following `tkn` command:
```bash
tkn taskrun logs --last -f
```{{execute}}
It may take a few moments before your `Task` completes. When it executes, it should
show the following output:
```console
[goodbye] Goodbye World!
```
In this section, we will create the pipeline combining the two tasks.
To create a `Pipeline`, create a Kubernetes object using the Tekton API with
the kind `Pipeline`. The following YAML file specifies a `Pipeline`.
```yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: hello-goodbye
spec:
tasks:
- name: hello
taskRef:
name: hello
- name: goodbye
runAfter:
- hello
taskRef:
name: goodbye
```{{copy}}
Write the YAML above to a file named `pipeline-hello-goodbye.yaml`, and apply it to your Kubernetes cluster:
```bash
kubectl apply -f pipeline-hello-goodbye.yaml
```{{execute}}
To run this pipeline with Tekton, you need to create a `pipelineRun`, which is
another Kubernetes object used to specify run time information for a `Pipeline`.
To view this `pipelineRun` object you can run the following Tekton CLI (`tkn`) command:
```bash
tkn pipeline start hello-goodbye --dry-run
```{{execute}}
After running the command above, the following `PipelineRun` definition should be shown:
```yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: hello-goodbye-run-
spec:
pipelineRef:
name: hello-goodbye
```{{copy}}
To use the `pipelineRun` above to start the `echo` `Pipeline`, you can either use
`tkn` or `kubectl`.
Start with `tkn`:
```bash
tkn pipeline start hello-goodbye
```{{execute}}
Start with `kubectl`:
```bash
# use tkn's --dry-run option to save the pipelineRun to a file
tkn pipeline start hello-goodbye --dry-run > pipelineRun-hello-goodbye.yaml
# create the pipelineRun
kubectl create -f pipelineRun-hello-goodbye.yaml
```{{execute}}
Tekton will now start running your `Pipeline`. To see the logs of the `pipelineRun`, run
the following `tkn` command:
```bash
tkn pipelinerun logs --last -f
```{{execute}}
It may take a few moments before your `Pipeline` completes. When it executes, it should
show the following output:
```console
[hello : hello] Hello World!
[goodbye : goodbye] Goodbye World!
[goodbye : goodbye] + set -e
[goodbye : goodbye] + echo Goodbye World!
```
# Additional resources
## Learn more about the Tekton Dashboard
https://github.com/tektoncd/dashboard
## Learn more about Tekton Pipelines
https://github.com/tektoncd/pipeline
## Get involved in the Tekton Community
https://github.com/tektoncd/community#want-to-get-involved
{
"title": "Tekton Dashboard",
"description": "Learn how to use the Tekton Dashboard!",
"difficulty": "Beginner",
"time": "30",
"details": {
"steps": [
{
"title": "Install the Tekton Dashboard",
"text": "step1.md",
"code": "init.sh"
},
{
"title": "Import Tekton Resources for MyApp",
"text": "step2.md"
},
{
"title": "Create the PipelineResource for MyApp",
"text": "step3.md"
},
{
"title": "Build & Deploy MyApp",
"text": "step4.md"
},
{
"title": "Monitor the PipelineRun & View MyApp",
"text": "step5.md"
}
],
"intro": {
"text": "intro.md"
},
"finish": {
"text": "finish.md"
},
"assets": {
"host01": [
{
"file": "*",
"target": "~/"
}
]
}
},
"environment": {
"uilayout": "terminal-iframe"
},
"backend": {
"imageid": "kubernetes",
"port": "80"
}
}
\ No newline at end of file
# Wait for Katacoda to initialize
sleep 1
# Start Kubernetes
launch.sh
# # Install Tekton Pipelines
# kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
# # Install Tekton Triggers
# kubectl apply --filename https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml
# # Install Tekton Dashboard
# kubectl apply --filename https://github.com/tektoncd/dashboard/releases/download/v0.3.0/dashboard-latest-release.yaml
# kubectl port-forward -n tekton-pipelines svc/tekton-dashboard 9097:9097 &
# Introduction to the Tekton Dashboard
In this tutorial, we will go through:
- Installing the Tekton Dashboard
- Importing a Tekton Pipeline using the Tekton Dashboard
- Creating a PipelineResource using the Tekton Dashboard
- Creating a PipelineRun using the Tekton Dashboard
- Monitoring the logs of a PipelineRun using the Tekton Dashboard
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
{
"name": "myapp",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
In this section, we will install and expose the Tekton Dashboard.
## Katacoda Kubernetes Cluster
It might take a minute or two for Katacoda to initialize your Kubernetes
cluster. When your cluster has been initialized, the
`kubectl cluster-info`{{execute}} command will return the cluster info.
Now, let's begin!
## Install the Tekton Dashboard Prerequisites
- [Tekton Pipelines](https://github.com/tektoncd/pipeline/blob/master/docs/install.md)
`kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.10.1/release.yaml`{{execute}}
- [Tekton Triggers](https://github.com/tektoncd/triggers/blob/master/docs/install.md) (optional)
`kubectl apply --filename https://storage.googleapis.com/tekton-releases/triggers/previous/v0.3.1/release.yaml`{{execute}}
Verify the pods are running:
`kubectl get pods -n tekton-pipelines`{{execute}}
## Install the Tekton Dashboard
For reference, the installation instructions are [here](https://github.com/tektoncd/dashboard#install-dashboard). To install the Tekton Dashboard, run the following
command:
`kubectl apply --filename https://storage.googleapis.com/tekton-releases/dashboard/previous/v0.5.3/tekton-dashboard-release.yaml`{{execute}}
<!-- `kubectl apply --filename https://storage.googleapis.com/tekton-releases/dashboard/latest/release.yaml`{{execute}} -->
Verify the Dashboard pod is running:
`kubectl get pods -n tekton-pipelines`{{execute}}
## Expose the Tekton Dashboard
### Install Ingress controller
Install the nginx ingress controller into the `ingress-nginx` namespace:
```bash
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud/deploy.yaml
```{{execute}}
Verify the ingress controller pod is running:
```bash
kubectl get pods -n ingress-nginx
```{{execute}}
### Create Ingress for the Tekton Dashboard
View the Tekton Dashboard Service:
`kubectl get svc tekton-dashboard -n tekton-pipelines`{{execute}}
The Tekton Dashboard Service is exposed on port `9097`. So, create an Ingress
for the `tekton-dashboard` Service on port `9097`:
```bash
cat << EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: tekton-dashboard
namespace: tekton-pipelines
spec:
backend:
serviceName: tekton-dashboard
servicePort: 9097
EOF
```{{execute}}
Verify the Ingress was created:
`kubectl get ingress -n tekton-pipelines`{{execute}}
## Open the Tekton Dashboard
Open the `Dashboard` tab in your Katacoda window, or click on the following link:
https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/.
It might take a minute for the ingress and Katacoda to get set up.
![Dashboard homepage screenshot](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/dashboard-homepage.png)
In this section, we will import a Tekton Pipeline to build and deploy the
demo Nodejs app called [MyApp](https://github.com/ncskier/myapp). MyApp displays
a random picture of a cat.
## Open the Tekton Dashboard Import Tekton resources page
Click on the following link to go directly to the Import Tekton resources page:
https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/#/importresources
Or navigate to the Import Tekton resources page in the Dashboard.
## Import the MyApp Tekton resources
We want to import the Tekton resources that are defined in the
[`tekton/`](https://github.com/ncskier/myapp/tree/master/tekton) directory of
MyApp. Import these Tekton resources into the `default` Namespace by
filling in the form with the following information:
Repository URL: `https://github.com/ncskier/myapp`{{copy}}
Namespace: `default`
Repository directory: `tekton/`{{copy}}
Service Account `tekton-dashboard`
The form should look like the following:
![Import Tekton resources screenshot.](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/import-tekton-resources.png)
Click the `Import and Apply` button.
## View the progress importing the Tekton resources
The Dashboard creates a PipelineRun to import the specified Tekton resources.
Click on the `View status of this run` link at the bottom of the page to view
the status of importing the Tekton resources for MyApp.
![View status of importing Tekton resources screenshot.](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/view-status-of-pipeline0.png)
The Tekton resources have been imported when the PipelineRun has completed.
![Import Tekton resources PipelineRun logs screenshot.](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/import-pipelinerun-logs.png)
In this section, we will create the git PipelineResource for MyApp. We will
later use this PipelineResource to run the Pipeline to build and deploy MyApp.
## Navigate to the PipelineResources page
Click on the following link to go directly to the PipelineResources page in the
Dashboard:
https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/#/namespaces/default/pipelineresources
Or navigate to the `default` Namespace's PipelineResources page in the Dashboard.
*Make sure the `default` Namespace is selected in the Namespace dropdown.*
![Navigate to PipelineResources page screenshot](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/pipeline-resources-page.png)
## Create the PipelineResource
Click on the blue `Create +` button in the upper right section of the page.
This opens a form to create a PipelineResource. We want to create a git
PipelineResource for the `master` branch of MyApp in the `default` namespace.
So, fill in the form with the following information:
Name: `myapp`{{copy}}
Namespace: `default`
Type: `Git`
URL: `https://github.com/ncskier/myapp`{{copy}}
Revision: `master`{{copy}}
The form should look like the following:
![Create PipelineResource form screenshot.](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/create-pipeline-resource-form.png)
Click the `Create` button to create the PipelineResource.
![Created PipelineResource screenshot.](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/created-pipeline-resource.png)
\ No newline at end of file
In this section, we will create the PipelineRun to build and deploy MyApp.
## Navigate to the PipelineRuns page
Click on the following link to go directly to the PipelineRuns page in the
Dashboard:
https://[[HOST_SUBDOMAIN]]-80-[[KATACODA_HOST]].environments.katacoda.com/#/namespaces/default/pipelineruns
Or navigate to the `default` Namespace's PipelineRuns page.
![Navigate to PipelineRuns page screenshot](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/pipeline-runs-page.png)
## Create the PipelineRun
Click on the blue `Create +` button in the upper right section of the page.
This opens a form to create a PipelineRun. The form is dynamic, and provides
PipelineResource and Param fields based on the selected Pipeline. We want to
create a PipelineRun in the `default` Namespace using the `myapp` Pipeline and
`myapp` PipelineResource. So, fill in the form with the following information:
Namespace: `default`
Pipeline: `myapp`
PipelineResources source: `myapp`{{copy}}
Leave the default values for the rest of the fields.
The form should look like the following:
![Create PipelineRun form screenshot.](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/create-pipeline-run-form.png)
Click the `Create` button to create the PipelineRun.
![Created PipelineRun screenshot.](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/created-pipeline-run.png)
In this section, we will view the PipelineRun logs to monitor its progress.
Then, we will open MyApp.
## Monitor the PipelineRun logs
View the PipelineRun logs for the MyApp PipelineRun by clicking on the link in
the creation notification at the top of the page.
![PipelineRun creation notification screenshot.](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/pipeline-run-created-notification.png)
Or select the PipelineRun from the list of PipelineRuns.
![View the running PipelineRun logs for MyApp screenshot.](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/pipeline-run-running.png)
Verify both the `build` and `deploy` tasks have passed.
![View the completed PipelineRun logs for MyApp screenshot.](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/pipeline-run-completed.png)
## Open the Deployed App
MyApp will be running on port `3000`. Click on the following link to open the
app:
https://[[HOST_SUBDOMAIN]]-3000-[[KATACODA_HOST]].environments.katacoda.com/
![View MyApp screenshot.](https://raw.githubusercontent.com/ncskier/katacoda/master/tekton-dashboard/images/view-myapp.png)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册