This scenario will take you through a recipe for delivering a microservice based on Python to Kubernetes. We look at a few effective techniques to package Python in an efficient container. Next, you create a CI/CD pipeline using Tekton, Kaniko is used in the pipeline to package a Python microservice in a container. The Tekton pipeline builds and delivers the application to Kubernetes.
The technologies you will touch are:
- Python microservice
- FastAPI with uvicorn
It's a lot to take in so take your time, and some tea, and settle in with this learning pathway.
Tekton is an open source project that formed as a subproject of the Knative project in March of 2019. Using established Kubernetes style declarations, whole pipelines can be declared. The pipelines run on Kubernetes like any other process. Each step runs as an independent container. Tekton also helps normalize and standardize the terms and methods for forming and running pipelines. Tekton pipelines can complement a variety of popular CI/CD engines. For more information also see the Continuous Delivery Foundation (CDF).
Tekton Pipelines is a Kubernetes extension that installs and runs on your Kubernetes cluster. It defines a set of Kubernetes Custom Resources that act as building blocks from which you can assemble CI/CD pipelines. Once installed, Tekton Pipelines becomes available via the Kubernetes CLI (kubectl) and API calls, just like pods and other resources. Tekton is open-source and part of the CD Foundation, a Linux Foundation project. -- Tekton Project
Within the pipeline is the Kaniko tool what builds OCI containers all within Kubernetes. Kaniko doesn't depend on a Docker daemon and references on Dockerfiles completely in a safe userspace.
You will learn:
- How to use FastAPI for developing a Python microservice
- How to distill a container that packages Python
- How to install a private registry with a UI
- How to define, run and observe a Tekton pipeline
- How to build a container with Kaniko
There are numerous, complementing, and competing ways to implement what you just learned here. You may be overwhelmed with decision fatigue while trying to invest in the best choice. Consider that Tekton with Kaniko is helping to standardize the language and architecture of pipelines that leverage the existing benefits of Kubernetes.
This tutorial shows how you can easily use Kubernetes as the underlying platform for running Tekton-based Pipelines. CI/CD is a great place for your team to start understanding how to leverage the distributed and high availability nature of Kubernetes.
In addition, there are various ways to write a microservice in Python and a few techniques to package it all in a container. The goal in this scenario is to press some good practices for distilling a container and effectively delivering a microservice to Kubernetes.
With these steps, you have learned:
- ✔ How to use FastAPI for developing a Python microservice
- ✔ How to distill a container that packages Python
- ✔ How to install a private registry with a UI
- ✔ How to define, run, and observe a Tekton pipeline
- ✔ How to build a container with Kaniko
- Tekton Project
- Continuous Deliver Foundation
- IBM tutorial on Tekton
- Kubernetes Podcast on Tekton
- Tekton Operator
- Tekton Plugin for VSCode
Python Pipeline to Kubernetes.
Your Kubernetes Cluster
For this scenario, Katacoda has just started a fresh Kubernetes cluster for you. Verify it's ready for your use.
kubectl version --short && \
kubectl get componentstatus && \
kubectl get nodes && \
The Helm package manager used for installing applications on Kubernetes is also available.
helm version --short
You can administer your cluster with the
kubectl CLI tool or use the visual Kubernetes Dashboard. Use this script to access the protected Dashboard.