Skip to content

Kubernetes Setup

Prerequisites

You should be able to access your personal Code VM via the web browser of your personal company’s choice.

Lab Exercise: Set Up your Personal Namespace

To get started we would like to set up a personal Kubernetes namespace on the provided cluster which will be used in the following exercises. Make yourself familiar with the layout of your workspace and ensure you are able to use the built-in terminal to execute shell command.

To test the connection to the Kubernetes cluster, execute the following command:

kubectl get node

You should see a list of all nodes within our cluster.

Exercise 0: Access the k8s Dashboard

To monitor your deployments and access pod command lines via your browser, you should be able to access the Kubernetes Dashboard at the following URL: Dashboard

To log in, you need to create a token for a pre-defines service account using the following command:

kubectl create -n kubernetes-dashboard token kubernetes-dashboard-admin --duration 8h

Copy the output of the command into the password field of the dashboard. You now should be able to see the whole cluster.

Dashboard Kubernetes Dashboard

Exercise 1: Create your Personal k8s Namespace

Use kubectl to create your personal namespace by using your assigned nickname in lowercase letters.

Solution

kubectl create namespace {your nick-name}

Exercise 2: Deploy a Debug Image

For later exercises we will use a custom image for testing and debugging. Create a simple deployment with this image in your personal namespace:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: debug-cli-user-conf
spec:
  storageClassName: default
  resources:
    requests:
      storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kafka-debug-cli
  labels:
    app: debug-cli
spec:
  replicas: 1
  selector:
    matchLabels:
      app: debug-cli
  template:
    metadata:
      labels:
        app: debug-cli
    spec:
      initContainers:
        - name: debug-cli-chown
          image: krassestecontainerreistry.azurecr.io/kafka-oauth-client:latest
          securityContext:
            privileged: true
            runAsUser: 0
            runAsGroup: 0
          command: [ "chown", "-R", "user:user", "/opt/user_conf" ]
          volumeMounts:
            - name: user-conf
              mountPath: /opt/user_conf
              readOnly: false
      containers:
        - name: debug-cli
          image: krassestecontainerreistry.azurecr.io/kafka-oauth-client:latest #TODO: replace ACR name
          volumeMounts:
            - name: user-conf
              mountPath: /opt/user_conf
              readOnly: false
          resources:
            limits:
              cpu: 500m
              memory: 500Mi
            requests:
              cpu: 100m
              memory: 50Mi
      volumes:
        - name: user-conf
          persistentVolumeClaim:
            claimName: debug-cli-user-conf
Solution

save the deployment specification in a file `./kafka-debug-cli.yaml`

kubectl apply -n YOUR_NAMESPACE -f ./kafka-debug-cli.yaml

Using the Kubernetes Dashboard, navigate to the pod kafka-debug-cli and open a shell:

Debug CLI Pod Kubernetes Dashboard - Debug CLI
Debug CLI Shell Kubernetes Dashboard - Debug CLI