Getting Started with Kubernetes: A Beginner's Guide to YAML, Linux, and Docker
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:
10.0.0.0 โ 10.255.255.255 (10.0.0.0/8)
172.16.0.0 โ 172.31.255.255 (172.16.0.0/12)
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.
- LinkedIn: [https://www.linkedin.com/in/anas133/]
Subscribe to my newsletter
Read articles from Anas directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by