Skip to main content

Kubernetes Cheat Sheet

Kubernetes Cheat Sheet: Essential Concepts and Commands

Kubernetes, the popular container orchestration platform, is known for its complexity as well as its power. Understanding its core concepts and mastering its command line interface can greatly improve efficiency and productivity when managing containerized applications. This article provides a quick overview of key Kubernetes concepts followed by a comprehensive cheat sheet of commands.

Key Kubernetes Concepts

  1. Pods: The smallest deployable units created and managed by Kubernetes, a Pod is a group of one or more containers (such as Docker containers), with shared storage/network, and a specification for how to run the containers.

  2. Services: An abstract way to expose an application running on a set of Pods as a network service. With Kubernetes you don't need to modify your application to use an unfamiliar service discovery mechanism.

  3. Deployments: Manage the deployment and scaling of a set of Pods, and provide declarative updates to Pods along with a lot of other useful features.

  4. Nodes: Worker machines in Kubernetes, which host the Pods that are the components of the application workload.

  5. Cluster: A set of Nodes that run containerized applications managed by Kubernetes.

  6. Namespaces: Kubernetes supports multiple virtual clusters backed by the same physical cluster. These virtual clusters are called namespaces.

  7. Volumes: A directory, possibly with some data in it, which is accessible to the containers in a pod.

  8. ConfigMaps and Secrets: Kubernetes objects that allow you to store and manage sensitive information, such as passwords, OAuth tokens, and ssh keys.

Kubernetes Command Line Interface (kubectl)

kubectl is the command line tool for Kubernetes. It allows you to run commands against Kubernetes clusters for managing resources, viewing logs, and other maintenance tasks. Here’s a cheat sheet of essential kubectl commands:

CommandDescriptionExample Usage
kubectl getList resourceskubectl get pods
kubectl describeShow detailed information about a resourcekubectl describe nodes my-node
kubectl createCreate a resource from a file or stdinkubectl create -f my-resource.yaml
kubectl applyApply a configuration to a resource by filename or stdinkubectl apply -f ./
kubectl deleteDelete resources by filenames, stdin, resources and names, or by resources and label selectorkubectl delete -f ./my-resource.yaml
kubectl logsPrint the logs for a container in a podkubectl logs my-pod
kubectl execExecute a command in a containerkubectl exec -ti my-pod -- bash
kubectl runRun a particular image on the clusterkubectl run my-pod --image=myimage
kubectl exposeExpose a resource as a new Kubernetes servicekubectl expose deployment my-dep --port=8080
kubectl scaleScale a resourcekubectl scale --replicas=3 deployment/my-dep
kubectl autoscaleAutoscale a deployment, replica set, or replication controllerkubectl autoscale deployment my-dep --min=10 --max=15 --cpu-percent=80
kubectl rolloutManage the rollout of a resourcekubectl rollout status deployment/my-dep
kubectl setSet specific features on objectskubectl set image deployment/my-dep my-container=myimage:latest
kubectl configModify kubeconfig fileskubectl config view
kubectl topDisplay Resource (CPU/Memory/Storage) usage.kubectl top pod
kubectl cluster-infoDisplay cluster infokubectl cluster-info
kubectl pluginProvides utilities for interacting with plugins.kubectl plugin list
kubectl attachAttach to a running container.kubectl attach my-pod -i
kubectl patchUpdate field(s) of a resource using strategic merge patch.kubectl patch node my-node -p '{"spec":{"unschedulable":true}}'
kubectl labelUpdate the labels on a resource.kubectl label pods my-pod new-label=my-label
kubectl annotateUpdate the annotations on a resource.kubectl annotate pod my-pod icon-url=http://my-icon.com
kubectl port-forwardForward one or more local ports to a pod.

Comments

Popular posts from this blog

DevOps Vs DevSecOps

   DevOps and DevSecOps are two methodologies that have gained traction in the IT industry for streamlining software development and deployment. However, their approach to security and operations differs, making each suitable for different types of projects and organizational needs. Let's explore DevOps versus DevSecOps with a real-time example, focusing on their distinctions, integration, and practical applications. DevOps: The Foundation DevOps is a cultural and professional movement that emphasizes collaboration and communication between software developers and other IT professionals while automating the process of software delivery and infrastructure changes. It aims to shorten the development life cycle and provide continuous delivery with high software quality. Core Principles: Continuous Integration and Continuous Deployment (CI/CD): Automate building, testing, and deployment of applications. Collaboration: Breaking down silos between teams (developers, IT operations...

Deploying a Node.js project to Azure App Services using Azure DevOps pipelines

Deploying a Node.js project to Azure App Services using Azure DevOps pipelines is a robust way to automate deployment processes and integrate continuous integration and deployment (CI/CD) practices into your workflow. This guide will walk you through the setup of an Azure DevOps pipeline to deploy a Node.js application from GitHub or Azure Repos to Azure App Services. Prerequisites Before you begin, ensure you have the following: An Azure account. You can sign up for a free account here . A GitHub or Azure Repos account with your Node.js project. An Azure DevOps account. Create one here if you don't have it. Step 1: Prepare Your Node.js Application Make sure your Node.js application is ready and includes a package.json file in the root. This file is crucial as it contains dependency information and scripts needed for your application. Step 2: Create an Azure Web App Log into Azure Portal: Visit https://portal.azure.com . Create a Web App: Click on "Create a resource". ...

Git Cheat Sheet

  Git Cheat Sheet Category Command Description Setup git config --global user.name "[name]" Set a name that will be attached to your commits and tags. git config --global user.email "[email]" Set an email that will be attached to your commits and tags. git init Initialize a new git repository in the current directory. git clone [url] Clone a repository into a new directory. Stage & Snapshot git status Show modified files in the working directory, staged for your next commit. git add [file] Add a file as it looks now to your next commit (stage). git reset [file] Unstage a file while retaining the changes in the working directory. git diff Show diff of what is changed but not staged. git diff --staged Diff of what is staged but not yet committed. git commit -m "[message]" Commit your staged content as a new commit snapshot. Branch & Merge git branch List all of the branches in your repo. git branch [name] Create a new branch at the current commit. gi...