Sấu Gấu Blog


K8s Installation

Pre-requisites

Enable IPv4 packet forwarding
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
EOF
# Apply the changes
sudo sysctl --system
# Verify the changes
sysctl net.ipv4.ip_forward
Enable br_netfilter module
Required for kube-proxy in iptables mode to properly handle network policies in Kubernetes clusters.
sudo modprobe br_netfilter
# Verify the changes
lsmod | grep br_netfilter# If doesn't show anything, then the module is not loaded
# Make sure the module is loaded on boot
sudo tee /etc/modules-load.d/k8s.conf <<EOF
br_netfilter
EOF

Useful commands

Docker Script
docker ps
docker run --rm --network <network_name> --name <container_name> -p <host_port:container_port> <options> <image_name> <new_command>
# rm flag automatically removes the container when it stops
docker exec -it <container_id> /bin/bash
# i flag interactive, t flag terminal
docker cp <container_id_or_name>:<path_inside_container> <path_on_host>
Network related commands
docker network ls
docker network create <network_name>
docker network rm <network_name>
docker network inspect <network_name>
docker network prune

Image related commands
docker image ls
docker image rm <image_id>
docker image prune # prune image with no tag
docker image inspect <image_id>
docker image pull <image_name>
docker image push <image_name>
docker image tag <image_id> <new_image_name>
docker image build -t <image_name> <path_to_dockerfile>
docker image history <image_name>
docker image save -o <output_file> <image_name>
docker image load -i <input_file>
docker image export -o <output_file> <container_id>
docker image import -i <input_file>
docker images --digests
docker images --filter=reference='<image_name>

K8s Script
# context is used to decide which api does kubectl interact with
kubectl config get-contexts
kubectl config use-context <context>
kubectl config current-context

kubectl run <pod_name> --image=<image_name>
kubectl get deployments
kubectl delete deployment <deployment-name>
kubectl get pods
kubectl describe pod <pod-name>
kubectl logs pod <pod-name> -c <container-name>
kubectl delete pod <pod-name>

kubeadm token create --print-join-command

GCP
gcloud container clusters get-credentials CLUSTER_NAME --region REGION

Helm Script
helm repo add <repo_name> <repo_url>
helm repo update
helm search repo <chart_name>
helm install <release_name> <chart_name> [--values <values_file>]
helm upgrade <release_name> <chart_name> [--values <values_file>]
helm uninstall <release_name>
helm list
helm get all <release_name>
helm status <release_name>
helm template <chart_name> [--values <values_file>]
helm lint <chart_directory>
helm dependency update <chart_directory>

Ngày đăng: April 14, 2025
84 total views

Comment

Hiện tại chưa có comment nào...