Getting Started with Kubernetes: A Beginner's Guide to YAML, Linux, and Docker

AnasAnas
7 min read

Kubernetes (K8s)

๐‘ซ๐’†๐’—๐’†๐’๐’๐’‘๐’†๐’… ๐’ƒ๐’š ๐‘ฎ๐’๐’๐’ˆ๐’๐’†: Kubernetes, commonly referred to as K8s, was developed by Google, with predecessors Borg and Omega for managing large-scale data processing.

๐Ž๐ฉ๐ž๐ง ๐’๐จ๐ฎ๐ซ๐œ๐ž: Open-sourced in 2014 and maintained by the Cloud Native Computing Foundation (CNCF).

๐๐ฎ๐ซ๐ฉ๐จ๐ฌ๐ž: Automates the deployment, scaling, and management of containerized applications.

Kubernetes is an open-source container orchestration platform designed to automate deploying, scaling and managing containerized applications.

โ–ช๏ธ It provides a framework to run distributed systems resiliently.

โ–ช๏ธ Kubernetes uses a declarative approach to configuration.

โ–ช๏ธ Users define the desired state of their applications and infrastructure, and Kubernetes continuously works to maintain that state.

๐˜๐€๐Œ๐‹ (๐˜๐€๐Œ๐‹ ๐€๐ข๐ง'๐ญ ๐Œ๐š๐ซ๐ค๐ฎ๐ฉ ๐‹๐š๐ง๐ ๐ฎ๐š๐ ๐ž)

Human-Readable: YAML is a human-readable data serialization format used for configuration files.

CASE SENSITIVE: Relies on indentation for structure.

QUOTES: Special characters like @ and # require quotes.

EXTENSIONS: Files can have .yaml or .yml extensions.

๐’๐ญ๐ซ๐ฎ๐œ๐ญ๐ฎ๐ซ๐ž:
Lists: Represented by a single hyphen (-).
Documents: Start with three hyphens (---).

Some Linux command :

ls


ls -a ๐Ÿง‘โ€๐Ÿ’ป      #Lists all files, including hidden ones.


ls -ll ๐Ÿง‘โ€๐Ÿ’ป  # List files and directories in a long format, including file type, permissions, number of hard links, owner and group names, file size in bytes, and last modification time.


or ls -ltr ๐Ÿง‘โ€๐Ÿ’ป   #  List files and directories in a long format, sorted by last modification time (oldest first).


 or ls -la ๐Ÿง‘โ€๐Ÿ’ป  # List all files and directories, including hidden files and directories, in a long format.


or ls -lh ๐Ÿง‘โ€๐Ÿ’ป  # List files and directories in a long format, with file sizes displayed in a human-readable format (e.g., bytes, kilobytes, megabytes, gigabytes).


touch anas.txt ๐Ÿง‘โ€๐Ÿ’ป  # Create a new empty file
nano  ๐Ÿง‘โ€๐Ÿ’ป # Open a text editor to create or edit a file
vim๐Ÿง‘โ€๐Ÿ’ป   # Open a text editor to create or edit a file

ps๐Ÿง‘โ€๐Ÿ’ป  # Display information about running processes

ps -ef ๐Ÿง‘โ€๐Ÿ’ป   #displays a list of all running processes on the system, including their process ID, parent process ID, CPU usage, memory usage, and command name.

ps aux ๐Ÿง‘โ€๐Ÿ’ป   # Display detailed information about all running processes

pstree ๐Ÿง‘โ€๐Ÿ’ป    # Display a tree-like view of running processes

ps -t -u syslog ๐Ÿง‘โ€๐Ÿ’ป   # Display information about processes running on a specific terminal, owned by a specific user

# This is to encode

๐Ÿง‘โ€๐Ÿ’ปecho anas | base64
result : W5hcwo=

# This is for decode
๐Ÿง‘โ€๐Ÿ’ปecho "W5hcwo=" | base64 --decode
result : anas 


# display the first 10 lines of a file

๐Ÿง‘โ€๐Ÿ’ปhead anas.txt # used when we have to see configurations files


# Display the last 10 lines of a file

๐Ÿง‘โ€๐Ÿ’ปtail anas.txt # used when we have see logs



# Networking commands
๐Ÿง‘โ€๐Ÿ’ปtcpdump    #Captures network traffic.

# If we want to see just 10 packets
๐Ÿง‘โ€๐Ÿ’ปtcpdump -c 10

#
๐Ÿง‘โ€๐Ÿ’ปtcpdump -c 2 -w anas.txt # This will return something "enp1s0"


๐Ÿง‘โ€๐Ÿ’ปtcpdump -i enp1s0 -c 2 -w anas.txt   #Captures 2 packets from the enp1s0 interface and writes them to a file named anas.txt.

# stream operator

๐Ÿง‘โ€๐Ÿ’ปtcpdump -i enp1s0 -c 2 > anas.txt     #Overwrites the contents of anas.txt with the output of tcpdump.
๐Ÿง‘โ€๐Ÿ’ปtcpdump -i enp1s0 -c 2 >> anas.txt     #Appends the output of tcpdump to the end of anas.txt.

## important commands


# used when you want to communicate directly with containers



๐Ÿง‘โ€๐Ÿ’ปjournalctl:   #allows you to query and display log messages from the systemd journal.


# Display all log messages

๐Ÿง‘โ€๐Ÿ’ปjournalctl



# Display log messages for a specific boot

๐Ÿง‘โ€๐Ÿ’ปjournalctl -b


๐Ÿง‘โ€๐Ÿ’ปjournalctl -u docker   #shows logs for the Docker service.



๐Ÿง‘โ€๐Ÿ’ปcrictl  # A CLI for CRI-compatible container runtimes, used for troubleshooting and managing containers.



๐Ÿง‘โ€๐Ÿ’ปcrictl pods   # List all pods


# List all containers

๐Ÿง‘โ€๐Ÿ’ปcrictl containers


๐Ÿง‘โ€๐Ÿ’ปcrictl ps -a    #list all containers on a Kubernetes node


๐Ÿง‘โ€๐Ÿ’ปcrictl logs "container id paste here"



# ctr is specifically used for containerd
# List all containers

๐Ÿง‘โ€๐Ÿ’ปctr containers

# Create a new container

๐Ÿง‘โ€๐Ÿ’ปctr create <container_id> <image>

# Start a container

๐Ÿง‘โ€๐Ÿ’ปctr start <container_id>

# Stop a container

๐Ÿง‘โ€๐Ÿ’ปctr stop <container_id>

# Delete a container

๐Ÿง‘โ€๐Ÿ’ปctr delete <container_id>




## read about systemd
cd /etc/systemd
# in this location there is file called journald.conf which journal daemon which means keep running

#

๐Ÿง‘โ€๐Ÿ’ปjournalctl --no-pager

 #displays all log messages from the systemd journal without using a pager.
#

๐Ÿง‘โ€๐Ÿ’ปjournalctl --since yesterday
#displays log messages from the systemd journal since yesterday.

# -o means output

๐Ÿง‘โ€๐Ÿ’ปjournalctl --since yesterday -o json-pretty

#display JSON format with pretty-printing.

Kubernetes Release Cycle:

Its cycle is of 4 months

https://www.kubernetes.dev/resources/release/

Kubernetes is not just container orchestration it is much more than that.

You can:

  • run it on your own cloud or

  • Own your local machine

  • On public cloud provides as well

  • You can migrate from one provider to another

  • When talking about services, kubernetes can replicate those, scale and put on dedicated servers and stuff and the zero downtime deployment and fault tolerance and self healing containers, you can use volumes, some external storage, It also provides load-balancing, can access logs and service discovery, can also store the secret information

Minikube

Minikube is a tool that allows you to run a single-node Kubernetes cluster on your local machine. It's a great way to get started with Kubernetes

it's not suitable for production environments.

minikube start   #Start a local Kubernetes cluster using Minikube.
minikube stop    #Stop the local Kubernetes cluster.
minikube delete   #Delete the local Kubernetes cluster
minikube kubectl -- get pods    #Run kubectl with the Minikube cluster and list all pods.

minikube start --feature-gates=EphemeralContainers=true    #Enable the EphemeralContainers feature gate in Minikube.

Kubeadm

Kubeadm is a tool that helps you create and manage Kubernetes clusters.
It's a more advanced tool than Minikube, and it's designed for production environments.

Kubeadm allows you to create multi-node clusters, and it provides more features and customization options than Minikube.

kubeadm init   #Initialize a new Kubernetes cluster.
kubeadm join <master-node>:<port>    #Join a node to an existing Kubernetes cluster.

kubeadm upgrade apply <version>    #Upgrade the Kubernetes cluster to a new version.
kubeadm reset    #Reset the Kubernetes cluster to its default state.

kubectl

Kubectl is the command-line tool for interacting with Kubernetes clusters. It's used to deploy, manage, and scale applications on a Kubernetes cluster. Kubectl is not a tool for creating or managing clusters, but rather for interacting with existing clusters.

kubectl get pods    #List all pods in the current namespace.
kubectl describe pod <pod-name>    #Display detailed information about a pod.
kubectl create deployment <deployment-name> --image=<image-name>    #Create a new deployment.

kubectl apply -f <configuration-file>    #Apply a configuration file to the cluster
kubectl get nodes   #List all nodes in the cluster.

I'm glad you enjoyed our conversation about tcpdump, journalctl, crictl, ctr, Minikube, kubectl, and kubeadm commands.

Let's stay connected and continue to learn from each other. If you have any more questions or topics you'd like to discuss, feel free to reach out to me anytime.

  • RFC 1918

    RFC 1918 is a standard from the Internet Engineering Task Force (IETF) that defines a set of IP address ranges for use in private networks. Published in 1996, RFC 1918 titled "Address Allocation for Private Internets" specifies IPv4 address ranges that are not routable on the public internet and are reserved solely for internal network use. Devices on a local network using these addresses can communicate with each other but require Network Address Translation (NAT) to access the internet.

    RFC 1918 Private IP Address Ranges

    RFC 1918 defines the following private IP address ranges:

    1. 10.0.0.0 โ€“ 10.255.255.255 (10.0.0.0/8)

    2. 172.16.0.0 โ€“ 172.31.255.255 (172.16.0.0/12)

    3. 192.168.0.0 โ€“ 192.168.255.255 (192.168.0.0/16)

Each of these ranges is designated for different sizes of networks:

  • 10.0.0.0/8: Suitable for large networks, with approximately 16 million addresses.

  • 172.16.0.0/12: Ideal for medium-sized networks, with around 1 million addresses.

  • 192.168.0.0/16: Commonly used in home and small office networks, offering around 65,000 addresses.

Purpose of RFC 1918 Addresses

RFC 1918 addresses are essential for:

  • Address Conservation: They help conserve IPv4 addresses, which are limited in supply.

  • Internal Security: Private IPs are shielded from the public internet, adding a layer of security.

  • Local Network Management: They allow organizations to build internal networks without needing unique, publicly routable IP addresses.

Network Address Translation (NAT) with RFC 1918

Devices on an internal network using RFC 1918 IP addresses require NAT to communicate with the public internet. NAT translates these private addresses to a public IP when connecting to the outside world, allowing devices with private addresses to share a single or small pool of public IP addresses.

Key Points

  • Non-routable on the Internet: These IP ranges can only be used within private networks.

  • Widely Used in LANs: Common in enterprise, home, and small office LANs.

  • Requires NAT for Internet Access: Allows internal devices to access the internet through NAT.

RFC 1918 is critical to how internal networks are structured, and it remains a foundational component in modern networking.

0
Subscribe to my newsletter

Read articles from Anas directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Anas
Anas