Kubernetes
Docker, Kubernetes, and Kali Linux Containers
Lesson Objectives:
By the end of this class, students will be able to:
Understand basic Docker concepts and commands
Grasp fundamental Kubernetes concepts
Deploy a simple application to Kubernetes
Create a Kali Linux container and deploy it to a Kubernetes cluster
Lesson Outline:
Introduction to Docker
Introduction to Kubernetes
Deploying a Simple Application to Kubernetes
Building and Deploying a Kali Linux Container in Kubernetes
Detailed Lesson Plan:
1. Introduction to Docker
a. What is Docker?
Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker's methodologies for shipping, testing, and deploying code, you can significantly reduce the delay between writing code and running it in production.
Docker's container-based platform allows for highly portable workloads. Docker containers can run on a developer's local laptop, on physical or virtual machines in a data center, on cloud providers, or in a mixture of environments.
b. Basic Docker Concepts
Images
Containers
Dockerfile
Docker Hub
Client
Docker Run: Command used to run a container.
Docker Build: Command used to build an image from a Dockerfile.
Docker Pull: Command used to pull an image from a registry.
Docker Host
Docker Daemon: The core component that manages Docker objects (images, containers, networks, and volumes).
Interacts with client commands to run, build, and pull images.
Images: Pre-configured templates used to create containers.
Examples in the diagram include Python, Redis, and a generic image.
Containers: Instances created from Docker images.
These are the actual running instances of applications or services.
Registry
Images: Stored Docker images available for pulling.
Examples in the diagram include NGINX, Ubuntu, PostgreSQL, and a generic image.
Extensions: Additional tools or services that extend Docker functionality.
Examples include JFrog and others.
Plugins: Plugins that integrate with Docker to provide additional capabilities.
Examples include Grafana and others.
Interaction Flow
Docker Build: The client sends a build command to the Docker daemon, which builds an image and stores it locally.
Docker Pull: The client sends a pull command to the Docker daemon, which fetches an image from the registry and stores it locally.
Docker Run: The client sends a run command to the Docker daemon, which creates and starts a container from a specified image.
c. Basic Docker Commands
d. Creating a Simple Dockerfile
2. Introduction to Kubernetes
a. What is Kubernetes?
Kubernetes is a powerful and widely used open-source platform for managing containerized workloads and services. It is a portable and extensible platform that facilitates declarative configuration and automation. Its services, support, and tools are widely available and have a rapidly growing ecosystem.
Containers are an excellent way to bundle and run your applications but they require management. Kubernetes is the de-facto standard for container orchestration and management. It provides a comprehensive platform for deploying, scaling, and managing containerized applications.
b. Kubernetes Architecture
Master node components
API Server
etcd
Scheduler
Controller Manager
Worker node components
Kubelet
Kube-proxy
Container runtime
c. Basic Kubernetes Concepts
Pods
Deployments
Services
Namespaces
d. Basic Kubernetes Commands
3. Deploying a Simple Application to Kubernetes
a. Creating a Simple Web Application
Create a simple "Hello World" web application using a language of choice (e.g., Python with Flask).
b. Dockerizing the Application
Create a Dockerfile for the application:
Build and push the Docker image:
c. Creating Kubernetes Deployment and Service YAML
Create a file named deployment.yaml
:
This Kubernetes configuration file defines a Deployment and a Service for a Flask application. The Deployment named "flask-app" ensures that three replicas of the pod are running, each using the Docker image we pushed earlier username/my-flask-app:v1
and exposing port 5000. The Service named "flask-app-service" uses a LoadBalancer to expose the application to the outside world, forwarding traffic from port 80 to port 5000 on the pods, ensuring external accessibility and load balancing.
d. Deploying the Application
4. Building and Deploying a Kali Linux Container in Kubernetes
a. Creating a Kali Linux Dockerfile
Create a file named Dockerfile-kali
:
This Dockerfile creates a Docker image based on the kalilinux/kali-rolling
image. It updates the package list and installs basic tools like nmap
and metasploit-framework
, then cleans up the package lists to reduce image size. A non-root user named "kali" is created and set as the default user. The working directory is set to /home/kali
, and the container runs with the command /bin/bash
by default.
b. Building and Pushing the Kali Linux Image
c. Creating Kubernetes Deployment for Kali Linux
Create a file named kali-deployment.yaml
:
This Kubernetes configuration file defines a Deployment for a custom Kali Linux application. The Deployment named "kali-deployment" ensures that one replica of the pod is running, using the Docker image username/kali-custom:v1
. The pod is configured to run with the command "/bin/sleep", "infinity"
, effectively keeping the container running indefinitely. The pod is labeled with app: kali
for identification and management purposes.
d. Deploying Kali Linux to Kubernetes
e. Accessing the Kali Linux Container
Further Practice
Customize the Kali Linux container with additional tools
Create a persistent volume for the Kali Linux container to store data
Set up network policies to restrict access to the Kali Linux container
Explore Kubernetes security best practices when dealing with potentially sensitive containers
Last updated