Mi Primera Pipeline
Sabiendo que los pipelines son tasks agrupadas vamos directo al punto. Si las tasks son pods, entonces un pipeline tendría que generar varios pods. Vamos a comprobarlo.
cat <<EOF > pipeHW.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: hello-pipeline
spec:
# Si pipeline usa tasks vamos a reutilizar las tasks que ya tenemos creadas
tasks: # Espera una lista
- name: hello
taskRef: # Apuntando a una task existente
name: hello-task
# Podemos crear una task aquí directamente
- name: finaltask
taskSpec: # Creando una nueva task al vuelo definiéndola dentro del pipeline
steps:
- name: final-task
image: alpine
script: >
echo "final task finalizing"
EOF
k create -f pipeHW.yaml
pipeline.tekton.dev/hello-pipeline created
k get pipeline
NAME AGE
hello-pipeline 42s
# Aunque definimos una task dentro del pipeline no fue creada por separado para estar disponible.
# Para reutilización es bueno tener las tasks definidas por separado.
k get tasks
NAME AGE
hello-task 85m
hello-task2 65m
# Para ejecutar el pipeline necesitamos el pipelineRun
cat <<EOF > pipeRunHW.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: hello-pipeline-
spec:
pipelineRef:
name: hello-pipeline
EOF
k get pipelinerun
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME
hello-pipeline-q5c4f True Succeeded 22s 13s
El pipeline es un controlador para tasks, por lo que creará varios pods de tasks con el nombre del pipeline delante.
# pods con el prefijo hello-task fueron creados anteriormente
k get pods | grep hello
hello-pipeline-q5c4f-finaltask-pod 0/1 Completed 0 100s
hello-pipeline-q5c4f-hello-pod 0/1 Completed 0 100s
hello-task-46z7v-pod 0/1 Completed 0 81m
hello-task2-fg8gh-pod 0/2 Completed 0 70m
k logs hello-pipeline-q5c4f-hello-pod
Defaulted container "step-hello" out of: step-hello, prepare (init), place-scripts (init)
Hello World
k logs hello-pipeline-q5c4f-finaltask-pod
Defaulted container "step-final-task" out of: step-final-task, prepare (init), place-scripts (init)
final task finalizing
El consejo es siempre montar tasks que se convertirán en piezas de lego para montar un pipeline en el futuro.
Una vez más recordando que pipeline también es un recurso a nivel de namespace.
k get pipeline -n tekton-pipelines
No resources found in tekton-pipelines namespace.
k get pipeline -n default
NAME AGE
hello-pipeline 12m
Recordando tkn tenemos tkn pipeline.
tkn pipeline list
NAME AGE LAST RUN STARTED DURATION STATUS
hello-pipeline 26 minutes ago hello-pipeline-q5c4f 20 minutes ago 9s Succeeded
tkn pipeline list -n tekton-pipelines
No Pipelines found
tkn pipelinerun logs hello-pipeline-q5c4f
[finaltask : final-task] final task finalizing
[hello : hello] Hello World