Local Kubernetes Demo

Let's do a demo locally, to show the standard commands that one might run when interacting with Kubernetes.

Video

Commands

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/v1
kind: Deployment
metadata:
name: rasa-custom-model
labels:
app: rasa
spec:
replicas: 3
selector:
matchLabels:
app: rasa
template:
metadata:
labels:
app: rasa
spec:
containers:
- name: rasa-demo
image: koaning/rasa-demo
ports:
- containerPort: 8080
command: ["rasa", "run", "--enable-api", "--port", "8080", "--debug", "--verbose"]
---
apiVersion: v1
kind: Service
metadata:
name: rasa-web
spec:
ports:
- port: 8080
targetPort: 8080
selector:
app: rasa
type: 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 we re-run 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

Next steps.

In the next video, we'll talk about helm and why it solves the issue of connecting services to pods.

Exercises

Try to answer the following questions to test your knowledge.

  1. What might be the reason that kubectl get pods is not showing any pods you're interested in?
  2. What command do you need to fetch the logs out of a running pod?

2016-2022 © Rasa.