Local Kubernetes Demo
Let's do a demo locally, to show the standard commands that one might run when interacting with Kubernetes.
Locally we started a kubernetes cluster using kind.
../kub-tutorial/kind create cluster kubectl cluster-info --context kind-kind
Let's show some of the basic commands that you can run with kubernetes.
kubectl create namespace demo kubectl create --namespace demo deployment webstuff --image=nginx --replicas=3 kubectl --namespace demo get pods kubectl --namespace demo scale deployment webstuff --replicas=5 kubectl --namespace demo get pods kubectl --namespace demo scale deployment webstuff --replicas=1 kubectl --namespace demo get pods kubectl logs --tail=10 demo-997c454df-j7w72 kubectl --namespace demo delete deployment webstuff kubectl create namespace rasa kubectl get namespace kubectl delete namespace demo
Let's now consider what we might need to run a Rasa container though.
- We want to define the number of replicas upfront.
- We want to be able to define the resources that are needed.
- We want to declare a service that can route to our resources.
- We need to pass along a pre-trained Rasa model.
It's common that there are many settings you'd like to deploy, so
instead of using CLI commands you might use a
.yaml file instead.
That way we can store all of the deployment settings in one place
and that makes it easier to iterate. That's why we're going to be
working with deployments instead of launching pods manually.
We'll first create a manifest file that contains our pods and service.
---apiVersion: apps/v1kind: Deploymentmetadata:name: rasa-custom-modellabels:app: rasaspec:replicas: 3selector:matchLabels:app: rasatemplate:metadata:labels:app: rasaspec:containers:- name: rasa-demoimage: koaning/rasa-demoports:- containerPort: 8080command: ["rasa", "run", "--enable-api", "--port", "8080", "--debug", "--verbose"]---apiVersion: v1kind: Servicemetadata:name: rasa-webspec:ports:- port: 8080targetPort: 8080selector:app: rasatype: LoadBalancer
We can now apply our manifest.
kubectl --namespace rasa apply -f manifest.yaml kubectl --namespace rasa get pods
Once again, we can choose to add a replica to our manifest. After
kubectl --namespace rasa apply -f manifest.yaml we can
varify that the pods have changed via.
kubectl --namespace rasa get pods
Here's the table that we got as output. Yours will likely be different because the names have some randomness in them.
Let's now look at the logs in our of our pods.
kubectl --namespace rasa logs rasa-custom-model-7b5865fc6b-2g5rv
It seems to be running! Let's also inspect our sevices.
kubectl --namespace rasa get svc
We could set up an ingress for Kubernetes but since we're running locally on our laptop we'll be better off forwarding a port to our service instead.
kubectl --namespace rasa port-forward svc/rasa-web 8080:8080
In the next video, we'll talk about helm and why it solves the issue of connecting services to pods.
Try to answer the following questions to test your knowledge.
- What might be the reason that
kubectl get podsis not showing any pods you're interested in?
- What command do you need to fetch the logs out of a running pod?