Common Kubernetes Attacks and How to Fix Them Part 3: Setting Up a Test Kubernetes Environment

Welcome back to the series! In the previous post, we finished going over our core Kubernetes concepts and architecture. This time around we will go through how to set up a Kubernetes environment within Kali Linux to provide a test environment to demonstrate each set of vulnerabilities.

This guide walks you through the installation, configuration, and deployment of your first pod.

Install kubectl: This is the primary tool used to send commands to your Kubernetes cluster:

sudoapt-get install kubectl

Install minikube: Download and install the Debian package for the local cluster manager:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb

Configure Docker: Install the Docker engine and ensure that the user has the correct permissions to run containers without needing sudo every time

sudo apt-get update && sudo apt-get install docker.io
sudo groupadd docker
sudo usermod -aG docker kali
newgrp docker

Verify Docker: Run a test container to ensure the permissions are active

dockerrun hello-world

Once the infrastructure is ready, the cluster can be initialised using the following steps:

Start minikube: Initialise the local Kubernetes environment using Docker as the driver:

minikube start --driver=docker

Deploy a Pod: Kubernetes uses YAML files to define the desired state of the application. Save the following configuration as nginx.yaml:

apiVersion: v1
kind: Pod
metadata:
name: my-singular-pod
labels:
app: my-app
spec:
containers:
- name: nginx-container
image: nginx:latest
ports:
- containerPort: 80

Apply the configuration: Run the following command to instruct the cluster to create the pod.

kubectl apply -f nginx.yaml

To verify that the Kubernetes pod was spun up correctly run:

kubectl get pod

To verify that we can emulate a post pod compromise scenario, run the following command to create an interactive shell inside of the pod:

minikube kubectl exec -it my-singular-pod -- /bin/bash

To remove the example pod, run the following command:

minikube kubectl delete pod my-singular-pod

Apply the configuration: Run the following command to instruct the cluster to create the pod.

kubectl apply -f nginx.yaml

To verify that the Kubernetes pod was spun up correctly run:

kubectl get pod

To verify that we can emulate a post pod compromise scenario, run the following command to create an interactive shell inside of the pod:

minikube kubectl exec -it my-singular-pod -- /bin/bash

To remove the example pod, run the following command:

minikube kubectl delete pod my-singular-pod

Congratulations! If the above command worked, then you should have a working Kubernetes pod. Next time we will cover our first Kubernetes misconfiguration. We will go over how we can create the misconfiguration, how we can abuse the misconfiguration, and then we can go over how the identified misconfiguration can be fixed.

Until next time, take care!

Recent posts

Latest from us