Kubernetes Cheatsheet

Cheatsheet https://kubernetes.io/docs/reference/kubectl/cheatsheet/ Type kubectl in command prompt to get this - kubectl controls the Kubernetes cluster manager. Find more information at: https://kubernetes.io/docs/reference/kubectl/ Basic Commands (Beginner): create Create a resource from a file or from stdin expose Take a replication controller, service, deployment or pod and expose it as a new Kubernetes service run Run a particular image on the cluster set Set specific features on objects Basic Commands (Intermediate): explain Get documentation for a resource get Display one or many resources edit Edit a resource on the server delete Delete resources by file names, stdin, resources and names, or by resources and label selector Deploy Commands: rollout Manage the rollout of a resource scale Set a new size for a deployment, replica set, or replication controller autoscale Auto-scale a deployment, replica set, stateful set, or replication controller Cluster Management Commands: certificate Modify certificate resources. cluster-info Display cluster information top Display resource (CPU/memory) usage cordon Mark node as unschedulable uncordon Mark node as schedulable drain Drain node in preparation for maintenance taint Update the taints on one or more nodes Troubleshooting and Debugging Commands: describe Show details of a specific resource or group of resources logs Print the logs for a container in a pod attach Attach to a running container exec Execute a command in a container port-forward Forward one or more local ports to a pod proxy Run a proxy to the Kubernetes API server cp Copy files and directories to and from containers auth Inspect authorization debug Create debugging sessions for troubleshooting workloads and nodes events List events Advanced Commands: diff Diff the live version against a would-be applied version apply Apply a configuration to a resource by file name or stdin patch Update fields of a resource replace Replace a resource by file name or stdin wait Experimental: Wait for a specific condition on one or many resources kustomize Build a kustomization target from a directory or URL Settings Commands: label Update the labels on a resource annotate Update the annotations on a resource completion Output shell completion code for the specified shell (bash, zsh, fish, or powershell) Other Commands: api-resources Print the supported API resources on the server api-versions Print the supported API versions on the server, in the form of "group/version" config Modify kubeconfig files plugin Provides utilities for interacting with plugins version Print the client and server version information Usage: kubectl [flags] [options] Use "kubectl <command> --help" for more information about a given command. Use "kubectl options" for a list of global command-line options (applies to all commands). Describe items kubectl get all - describes all the entities(services, pods, deployments, replicasets etc) kubectl get pods - shows all the pods running for default namespace kubectl get svc - get all services kubectl get all rs - get all replica sets kubectl get pods -n <my-namespace> - shows running pods for <my-namespace> running. kubectl describe <resource-type> <resource-name> pod - kubectl describe pod my-pod service - kubectl describe service my-service deployment - kubectl describe deployment my-deployment namespace - kubectl describe namespace my-namespace configMap - kubectl describe configmap my-config node - kubectl describe node my-node ingress - kubectl describe ingress my-ingress statefulset - kubectl describe statefulset my-statefulset Delete resources kubectl delete pod <podname> -n <namespace> ...

13 min

Devops Roadmap

Consider the following below topics and sub-topics to learn and understand to get into Devops. Kubernetes Architecture Api Server - REST, watched by multiple items(kubelet, k-proxy), certificate for request etcd - key-value store, cluster in eks for HA Scheduler - taints, tolerations, affinity based scheduling Kube Controller Manager - state of pods and changes, both watch api server kubelet(run on each node) and interaction with containerd(it creates the container asked by scheduler) k-proxy - runs on each node, handles networking and DNS. Flat networking Deployment, pod, service, secret, configmaps (understand their working and connection) Ingress Controller and ingress resource (ingress, egress etc and what they are) commands to run inside container pod lifecycles pod, node networking(DNS, fqdn) Service Account, roles, clusterrole, rolebinding and clusterrolebinding NetworkPolicies and how they work Volumes (types, mount location) important Authorization, authentication and Admission controller Flow of request (refer to image in Documents/devops folder) CRDs Go deeper into more topics and its API conventions AWS Knowledge of cloud practitioner course Working and knowledge of EC2 Setup Patching Security Groups subnets userdata Networking Knowledge Public and private subnets(internet access to private subnets) NAT and gateways VPC endpoints ALB vs NLB vpc peering vs transit gateway Security groups and their port mapping CIDR block Route53 record types working and health checks(setting them up) monitoring route53 Cloudwatch logs creating dashboard understanding metrics and querying Web Server(Apache and Nginx) need of web server virtual hosting allow/deny IPs .htaccess and htpasswd reverse proxy Implement thread and other directives configure logging understand various log formats server logs, audit logs enable, check tracking of users Docker (containerization) need of docker docker networking (types of docker networks) docker commands and creating dockerfile Docker compose docker swarm volume mounts and their types port mapping (left host: right container) Meaning of commands like - ENTRYPOINT ARG (how its used) WORKDIR etc Jenkins and Gitlab Pipeline setup understand groovy syntax understand .gitlab-ci.yml file as well create own groovy scripts terraform what is IAAC and why IAAC is needed? create own tf code and store locally ADHOC iops and throughput mail configure, smtp, send mail redirects openSSL postfix(similar to sendMail) sftp in linux, add user ipsec, ACL, port forwarding port forwarding in nginx jumpbox private to public network understand kernel, patching Consul and Istio setup and service mesh store env in consul and update them try istio for more like request tracing ArgoCD: TODO Setup Argo later for CD as CI needs its own jenkins/gitlab pipeline First learn pipelines and then use ArgoCD later Programming Python Automate anything and everything with this. Create and focus on logic with this Golang learn this for long time future complex solution sbuild from python to this Things to be good at Linux Administration Monitoring CI & CD Pipelines Some sort of scripting General cloud knowledge of a specific provider Communication Integrations Development workflows Performance tuning (web server, network, database)

3 min

Common linux and git commands

Some common linux commands are - ls - show current files and directories ls -l - show files and directories with permissions cd - change directory hostname - shows the host device name ifconfig - display IP and MAC address top - show all running processes cat filename - shows the contents of the “filename” mkdir - create directories rm -rf dirname - removes directory and inside files. -r is for recursive and -f is for force. history - see the history of all the commands. ping host-ip - Check connectivity between hosts chmod 777 filename - Assign read, write and execute permissions(rwx) to owner, group and others. chmod -x filename - Remove execute functionality of file. chown - change owner and group ownership of file netstat -tulpn - check open ports which are listening of tcp and udp with their pid. tcp dump port_number - check packets incoming and outgoing to the given port number alias command to create a command alias such as alias lh="ls -lrth" and so later, when u do lh, it runs same as ls -lrth brctl show -Shows information about the bridge network and veth interfaces it is connected to and its attached ports of veth pair in kubernetes route- check the route table ip addr - Displays the addresses for every link configured on the system, same as ip a ip link sh - Inspect the network configuration within pod ethtool -S eth0 or veth12abcd - query or control network driver and hardware settings with statistics flag ip route sh - Show route table, same as route -n ping ip - shows connectivity to the IP(cannot use port) nc -vz ip_addr port - Checks tcp connectivity nc -vz 10.99.52.54 30080 traceroute - Shows route of packet flow traceroute ip w or sudo w - check current logged in session for terminal pv - monitor progress of a command execution pv file.tar.gz > /tmp/file.tar.gz htop - see current cpu utilization free -kh - see memory usage du -sh - see disk utilisation Git commands git rev-parse --short HEAD - get the latest commitId ...

3 min

Kubernetes Advanced Concepts

https://kubernetes.io/docs/tasks/administer-cluster/manage-resources/memory-default-namespace/ LimitRange If you mention the limits but not the requests then pod is assigned limit value as the request(for both memory and cpu) Make sure to have limits set for atleast memory and requests as well. You can set a default memory and cpu limit for a namespace as well. These are namespace scoped. A LimitRange provides constraints that can: Enforce minimum and maximum compute resources usage per Pod or Container in a namespace. Enforce minimum and maximum storage request per PersistentVolumeClaim in a namespace. Enforce a ratio between request and limit for a resource in a namespace. Set default request/limit for compute resources in a namespace and automatically inject them to Containers at runtime. Reference - https://kubernetes.io/docs/tasks/administer-cluster/limit-storage-consumption/ ...

9 min

Beyond the Hype: Practical Challenges in GenAI Development

LLMs are the talk of the town going on for for the past 3-4 years with stocks of anything related to AI skyrocketing and more and more startups using AI to build something that will change the world. Now, while the aim and ideas floating around seem optimistic with POCs supporting the optimism, the reality of current GenAI powered apps are not revolutionary and are rather thin layers over LLMs. Here are the reasons why I think that is the case - ...

February 1, 2025 · 16 min

Url Shortener System Design Implementation - Part 2

So the next steps after generating tests and testing the application is as follows - Build Dockerfile for the app and run the app locally with redis and mongodb running locally or via docker After testing them locally, run them inside docker-compose to understand docker networking and DNS resolution Build docker images with proper tags to be used for kubernetes deployment and upload to Dockerhub Install minikube and run it locally Generate YAML files for MongoDB and Redis with deployment and services configuration and run them stateless Note their FQDN <service>.<namespace>.svc.cluster.local and add them as K8s env variables to be used Create YAML file for FastAPI application with environment set and with deployment, service and ingress and apply it Check the application running and access it via command minikube tunnel Deploying to local Kubernetes Make sure to install minikube as per their documentation - https://minikube.sigs.k8s.io/docs/start/?arch=%2Fwindows%2Fx86-64%2Fstable%2F.exe+download ...

December 3, 2024 · 9 min

Url Shortener System Design Implementation - Part 1

Aim Design, develop and deploy a working url shortener service which is able to handle huge number of requests and processing with high availability and fault tolerance. Best code practices have to be followed with optimisations made on asynchronous implementation, tests, max retries, high availability etc We start with building a local app to be deployed on docker with mongodb and redis running locally or on docker. This will then be shifted to kubernetes cluster once it works with tests. ...

December 1, 2024 · 10 min

Advanced RAG Techniques Compared with Workflow Diagrams

There exist quite a number of RAG techniques aiming to improve chatbot systems to have better accuracy and relevance to questions being asked. Some of the popular techniques are - RAG Fusion Multi query Native RAG Stepback prompting Hierarchical indexes Document summary index + LLM rerank HyDe Query decomposition Refer to research paper with different RAG techniques compared are graded - https://arxiv.org/pdf/2404.01037 Here is how they compare to each other and what are the benefits and problems of each technique being used for implementing RAG based systems. ...

October 19, 2024 · 9 min

Building Advanced Chatbot On Personal Blog

So I have been working on GenAI applications for past few months and decided to build something using RAG. I could not think of some interesting resources so I decided to take my own blog content as the data to build my RAG chatbot on. Please note that the following content is going to be almost same as my medium blog - https://medium.com/@varunarora1408/building-rag-chatbot-on-my-personal-blog-ff89ac772c69 So, here was the rough idea that came to my mind to create this application- ...

September 29, 2024 · 16 min

Kubernetes nginx deployment on nodeport

Here is guide how you can easily deploy nginx web server on minikube locally with common kubernetes terms explaied as well in the tutorial. Nginx Deployment apiVersion: apps/v1 kind: Deployment metadata: name: my-nginx-deployment spec: replicas: 3 selector: matchLabels: app: nginx-deployment template: metadata: labels: app: nginx-deployment spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80 protocol: TCP resources: limits: cpu: "500m" # 500 milliCPU (0.5 CPU) memory: "512Mi" # 512 Mebibytes requests: cpu: "200m" # 200 milliCPU (0.2 CPU) memory: "256Mi" # 256 Mebibytes Note - we have to use apps/v1 for Deployment and metadata is very important. The name nginx-deployment in metadata refers to name of deployment. ...

September 21, 2024 · 3 min