Kubernetes

A brief overview of Kubernetes

What is Kubernetes?

  • Kubernetes is a container orchestration platform designed to automate the deployment, scaling, and management of containerized applications.

Kubernetes Terminology

  • An application gets deployed (encapsulated) into a Pod which is a single instance of an application

  • Pods exist on a Node

  • Multiple Nodes form a Cluster

Kubernetes Deployment Example

  • A Kubernetes Deployment file is created in YAML and provides a declarative way to specify the desired state of an application and its associated resources

# A basic Kubernetes deployment file that deploys 2 (replicas) containers

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tylers-deployment
  labels:
    app: tylers-app
spec:
  template:
    metadata:
      name: tylers-pod
      lables:
        app: tylers-app
      spec:
        containers:
          - name: tylers-container
            image: alpine:latest
  replicas: 2
  selector:
    matchLabels:
      app: tylers-app

Kubernetes Cheat Sheet

  • A handy list of common Kubernetes commands organized by type

Deployment Commands

# Deploy a container on a Pod
kubectl run <nameOfPod> --image <nameOfTheImageFromYourImageRepo>
	# kubectl run nginx --image nginx

# Deploy from a yaml file (apply and create are interchangable)
kubectl apply -f <fileName>.yaml

# Deploy a deployment type file
kubectl apply -f <fileName>.yaml

# View deployment
kubectl get deployments

# Edit a deployment
kubectl edit deployments <deploymentName>

# Apply a new update
kubectl apply -f <fileName>.yaml

# View deployment status
kubectl rollout status deployment/<deploymentName>

# View deployment history
kubectl rollout history deployment/<deploymentName>

# Rollback a deployment
kubectl rollout undo deployment/<deploymentName>

Node Commands

# Get nodes in cluster
kubectl get nodes

# Get OS of running nodes
kubectl get nodes --output wide # other options exist too e.g., json'

Pod Commands

# Get Pods
kubectl get pods

# Get details of a Pod
kubectl describe pods # <podName>

# Delete a pod (or pods if more than one is specified)
kubectl delete pod <podName> # <podName2> <podName3>

Replica Commands

# Get number of replicasets
kubectl get replicasets

# Get details of replicasets
kubectl describe replicasets # <replicaset name>

# Delete a replicaset (or sets if more than one is specified)
kubectl delete replicasets <replicasetName> # <replicasetName2>

# Edit an existing replicaset (this should take effect after changing the file)
kubectl edit replicasets <replicasetName> # then change the number to replicate

Service Commands

# Create a service
kubectl create -f <serviceDefinitionFile>

# View services
kubectl get serivces 

Troubleshooting Commands

# View pod logs
kubectl logs <podName> -n <namespace>

Useful Resources

Last updated