Geek Guy

Common Kubernetes Commands & Administrator Functions (cli commands)

Created: 2026-09-21
Scope: kubectl commands, administrator functions, multi-cloud platform comparisons


Executive Summary

Kubernetes administration revolves around the kubectl CLI tool and a set of higher-level management tools. This report documents the most common commands across all resource types, essential administrative workflows, and platform-specific considerations for AWS EKS, GCP GKE, and Azure AKS.


Core kubectl Commands by Resource Type

Pods

OperationCommandExampleUse Case
List podskubectl get podskubectl get pods -n kube-systemView all running pods
Describe podkubectl describe pod <name>kubectl describe pod nginx-deployment-7d66fb95bf-x2z4mFull pod status, events, conditions
Exec into podkubectl exec -it <pod> -- /bin/shkubectl exec -it nginx-pod -- shDebug application issues
Logskubectl logs <pod>kubectl logs app-12345 --tail=100View container output
Port-forwardkubectl port-forward svc/<svc> 8080:80kubectl port-forward pod/app-abc 3000:8080 -n devLocal development access
Attachkubectl attach <pod>kubectl attach debug-pod -t /bin/bashInteractive shell (same process)
Scale podskubectl scale deployment/<name> --replicas=Nkubectl scale deploy web --replicas=5Adjust pod count

Deployments & Workloads

OperationCommandExampleUse Case
Get deploymentskubectl get deploymentskubectl get deploy -o wideList all deployments
Describe deploymentkubectl describe deployment <name>kubectl describe deployment nginx-deployView rollout status, pod template
Apply manifestkubectl apply -f file.yamlkubectl apply -f deployment.yamlCreate/update resource from YAML
Rollout historykubectl rollout history deploy/<name>kubectl rollout history deploy/my-appSee revision history
Rollbackkubectl rollout undo deploy/<name>kubectl rollout undo deploy/backendRevert to previous revision
Scale deploymentkubectl scale deploy/<name> --replicas=Nkubectl scale deploy web --replicas=10Adjust replica count
Pause/resumekubectl pause deploy/<name> / kubectl unpause <name>Prevent rollout during updates

Services & Networking

OperationCommandExampleUse Case
Get serviceskubectl get svckubectl get svc -n prodList all services
Describe servicekubectl describe svc <name>kubectl describe svc web-ingressView endpoints, cluster IP
Port-forwardkubectl port-forward svc/<svc> 8080:80Local access to service
Service proxykubectl proxy /api/v1/namespaces/default/proxy/svc-name/HTTP proxy to service

Namespaces & Resources

OperationCommandExampleUse Case
List namespaceskubectl get nskubectl get ns --all-namespacesView all namespaces
Create namespacekubectl create namespace <name>kubectl create ns stagingIsolate workloads
Delete namespacekubectl delete ns <name>Cleanup namespace

ConfigMaps & Secrets

OperationCommandExampleUse Case
Get configmapskubectl get cmkubectl get cm -o yamlView configuration data
Create secretkubectl create secret generic <name> --from-file=key=value.txtStore sensitive data encrypted
Describe secretkubectl describe secret <name>Verify secret encoding

Persistent Volumes & Storage

OperationCommandExampleUse Case
Get PVs/PVCskubectl get pv,pvckubectl get pvc -o wideView storage claims
Describe PVkubectl describe pv <name>View capacity, access mode

Nodes & Clusters

OperationCommandExampleUse Case
Get nodeskubectl get nodeskubectl get nodes -o wideView node status, roles
Describe nodekubectl describe node <name>Full node info (conditions, taints)
Cordon nodekubectl cordon <node>kubectl cordon node-abc123Drain pod scheduling
Uncordon nodekubectl uncordon <node>Re-enable scheduling
Taint nodekubectl taint nodes <name> key=value:NoScheduleNode affinity enforcement
Drain nodekubectl drain <node> --ignore-daemonsetsSafe pod eviction before maintenance

RBAC & Authentication

OperationCommandExampleUse Case
Get roleskubectl get role,clusterrolekubectl get clusterrole system:node-proxier -o yamlView permission sets
Get bindingskubectl get rolebinding,clusterrolebindingSee who has what permissions
Create rolekubectl create role --verb=get,list --resource=pods --namespace=defaultDefine fine-grained permissions

Events & Debugging

OperationCommandExampleUse Case
Get eventskubectl get events -n <ns>kubectl get events -n prod --sort-by=.lastTimestampView recent cluster events
Describe pod (events)kubectl describe pod <name>Includes event history

Essential Administrator Functions

Cluster Provisioning & Configuration

# Create a new cluster with kubectl (requires kubeadm or cloud-native setup)
kubectl apply -f cluster.yaml  # Custom resource definition from CAPI

# Apply Kubernetes configuration from file
kubectl apply -f infrastructure-as-code/cluster.yaml

# Verify cluster health
kubectl get nodes
kubectl get pods -n kube-system

Cluster Upgrade & Maintenance

# Drain node for maintenance
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data

# Uncordon after maintenance
kubectl uncordon <node-name>

# Apply Kubernetes version upgrade (requires kubeadm or cloud provider tools)
# Cloud providers: use eksctl update-cluster-version, gcloud container clusters update, etc.

# Upgrade control plane components
kubectl apply -f patches/control-plane-upgrade.yaml

Backup & Recovery

# Export cluster resources to YAML files (backup)
kubectl get all --all-namespaces -o yaml > backup-$(date +%Y%m%d-%H%M%S).yaml

# Export specific resource types
kubectl get deployments,configmaps,secrets,pods,services,statefulsets,daemonsets \
    --all-namespaces -o yaml > full-cluster-backup.yaml

# Restore from backup (carefully!)
kubectl apply -f restore-20260921-143022.yaml

Monitoring & Observability

# Get resource usage across namespaces
watch -n 5 'kubectl top nodes'
watch -n 5 'kubectl top pods --all-namespaces'

# Describe metrics server (if installed)
kubectl get apiservice v1.metrics.k8s.io

# Check pod resource requests/limits
kubectl get pods --show-labels -o wide

Troubleshooting

# Identify unhealthy nodes
kubectl get nodes | grep NotReady

# Find pending pods and their reasons
kubectl get pods --field-selector=status.phase=Pending -o wide

# View events for a specific pod
kubectl describe pod <pod-name>

# Check container restart counts
kubectl get pods --no-headers -o custom="metadata.name,pod.ip,containers[0].restartCount" \
    | awk '{if ($3 > 0) print $1}'

Multi-Cloud Platform Comparison

AWS EKS (Elastic Kubernetes Service)

FeatureDetails
CLI Toolaws + eksctl for cluster management; kubectl for resource operations
Cluster creationeksctl create cluster --name my-cluster --region us-east-1 --nodes 3
Credentialsaws eks update-kubeconfig --name my-cluster
Control plane cost~$73/month (base control plane) + node costs
Default CNIAWS VPC CNI Plugin
Managed addonsAmazon VPC CNI, CoreDNS, kube-proxy, AWS Load Balancer Controller

Google Cloud GKE (Google Kubernetes Engine)

# Create a standard GKE cluster
gcloud container clusters create my-cluster \
    --region us-central1 \
    --num-nodes 3 \
    --machine-type e2-standard-4 \
    --cluster-version 1.32 \
    --enable-ip-alias

# Get credentials for kubectl
gcloud container clusters get-credentials my-cluster \
    --region us-central1

# Create a GKE Autopilot cluster (no node management)
gcloud container clusters create-auto my-autopilot-cluster \
    --region us-central1 \
    --release-channel regular
FeatureDetails
CLI Toolgcloud for cluster management; kubectl for resource operations
Cluster creationgcloud container clusters create my-cluster --num-nodes 3
Credentialsgcloud container clusters get-credentials my-cluster --region us-central1
Control plane cost$0.10/hour (standard) or Autopilot pricing model
Default CNIVPC-native (alias IPs per pod)
Managed addonsGKE Addons (CoreDNS, Kube-DNS, Cloud Run GCP-Gateway, etc.)

Azure AKS (Azure Kubernetes Service)

# Create resource group
az group create --name myResourceGroup --location eastus

# Create an AKS cluster
az aks create \
    --resource-group myResourceGroup \
    --name myAKSCluster \
    --node-count 3 \
    --node-vm-size Standard_DS3_v2 \
    --kubernetes-version 1.32 \
    --network-plugin azure \
    --enable-managed-identity \
    --generate-ssh-keys

# Get credentials for kubectl
az aks get-credentials \
    --resource-group myResourceGroup \
    --name myAKSCluster

# Verify connectivity
kubectl get nodes
FeatureDetails
CLI Toolaz (Azure CLI) + aks subcommand for cluster management; kubectl for resource operations
Cluster creationaz aks create --resource-group myRG --name myAKS --node-count 3
Credentialsaz aks get-credentials --resource-group myRG --name myAKS
Control plane costFree (managed by Azure) + node costs
Default CNIAzure CNI Overlay (pod IPs in VNet)
Managed addonsAzure Application Gateway, Azure Load Balancer, Azure DNS, Azure AD integration

Advanced Administration Tasks

Pod Lifecycle Management

# Restart a specific container in a pod
kubectl restart pod/<name> -c <container-name> -n <namespace>

# Exec into a running container with command override
kubectl exec -it nginx-deployment-7d66fb95bf-x2z4m -- /bin/sh

# Apply patches to running pods (rolling update)
kubectl apply -f patch.yaml

# Replace entire deployment with new spec
kubectl replace -f new-deployment.yaml --force-conflicts=false

Service Mesh & Traffic Management

# Get Ingress resources
kubectl get ingress -n <namespace>

# Describe an Ingress to see rules and backends
kubectl describe ingress my-ingress -n production

# Apply Istio virtual service (service mesh routing)
kubectl apply -f istio-virtual-service.yaml

# Port-forward from local machine to cluster service
kubectl port-forward svc/frontend 8080:80 --namespace=production

Cluster Autoscaling Configuration

# Get Horizontal Pod Autoscaler details
kubectl get hpa -n <namespace>

# Describe an HPA
kubectl describe hpa web-hpa -n production

# Scale a deployment using HPA metrics
kubectl autoscale deployment web --cpu-percent=70 --min=3 --max=10

Cluster Networking & Ingress Management

# Get all services and their endpoints
kubectl get svc,endpoint -o wide

# List all ingress resources
kubectl get ingress --all-namespaces -o wide

# Describe an ingress to see routing rules
kubectl describe ingress my-ingress

# Apply network policy (if using Calico/Cilium)
kubectl apply -f network-policy.yaml

Cluster Version & Patch Management

# Check cluster version
kubectl version --short

# Get Kubernetes component versions
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{": "}{.status.nodeInfo.kubeletVersion}{"\n"}{end}'

# Apply a patch to update specific components (requires appropriate RBAC)
kubectl apply -f patches/control-plane-patch.yaml

Cluster Resource Management & Monitoring

# Get resource requests and limits for all pods
watch -n 5 'kubectl top nodes'
watch -n 5 'kubectl top pods --all-namespaces'

# Check pod resource usage with details
kubectl get pods --no-headers -o custom="metadata.name,containers[0].resources.requests.cpu,containers[0].resources.limits.memory"

# Describe a node to see its capacity and allocatable resources
kubectl describe nodes <node-name>

Security & RBAC Administration

Role-Based Access Control (RBAC)

# Create a custom role for developers
cat <<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: production
  name: developer-role
rules:
- apiGroups: [""]
  resources: ["pods", "configmaps", "secrets"]
  verbs: ["get", "list", "watch", "create", "update"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  namespace: production
  name: developer-binding
subjects:
- kind: User
  name: jsmith
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: developer-role
  apiGroup: rbac.authorization.k8s.io
EOF

# Grant cluster-admin access (use sparingly!)
kubectl create clusterrolebinding admin-binding --clusterrole=cluster-admin \
    --user=kubernetes-admin

# List all roles and bindings in a namespace
kubectl get role,clusterrole,rolebinding,clusterrolebinding -A

# View who has access to what
kubectl auth can-i pods/exec --namespace=production

Security Contexts & Pod Security

# Apply a security context to a deployment
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: secure-app
spec:
  template:
    spec:
      containers:
      - name: app
        image: myapp:v1.0
        securityContext:
          runAsNonRoot: true
          runAsUser: 1000
          allowPrivilegeEscalation: false
          readOnlyRootFilesystem: true
          capabilities:
            drop:
              - ALL
EOF

# Apply a Pod Security Standard (PSS) policy
kubectl apply -f policies/policy.yaml

Secret Management

# Create an encrypted secret from a file
kubectl create secret generic db-credentials \
    --from-file=username=dbuser.txt \
    --from-file=password=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)

# Create a TLS secret from certificate files
kubectl create secret tls tls-secret \
    --cert=tls.crt \
    --key=tls.key \
    --namespace=production

# List all secrets (encrypted at rest by default)
kubectl get secrets --all-namespaces -o wide

Troubleshooting Command Patterns

Pod Not Starting

# Check pod status and reason for failure
kubectl get pods -A | grep -v Running

# Get detailed events about the failed pod
kubectl describe pod <pod-name>

# Check container logs (last 100 lines)
kubectl logs <pod-name> --tail=100

# Check if the image pulled successfully
kubectl describe pod <pod-name> | grep -i "ImagePull"

# Restart a failing container
kubectl rollout restart deployment/<deployment-name>

Service Connectivity Issues

# Verify service endpoints exist
kubectl get svc,endpoint -n production

# Port-forward to the service for local debugging
kubectl port-forward svc/my-service 8080:80 -n production

# Test connectivity from within a pod
kubectl run debug --image=busybox \
    --rm -it --restart=Never \
    -- /bin/sh -c "wget -qO- http://my-service"

# Check service DNS resolution
kubectl run dns-test --image=dnsutils \
    --rm -it --restart=Never \
    -- nslookup my-service.production.svc.cluster.local

Resource Pressure & Node Issues

# Identify nodes with high load or in NotReady state
kubectl get nodes | grep -v Ready

# Describe a problematic node
kubectl describe node <node-name>

# Drain and uncordon a node for maintenance
kubectl drain <node-name> --ignore-daemonsets --delete-emptydir-data
kubectl uncordon <node-name>

# Check if pods are being evicted due to pressure
kubectl get events --sort-by=.lastTimestamp | grep -i "evict\|pressure"

Quick Reference Commands

Daily Admin Checklist

# 1. Verify cluster health
kubectl get nodes
kubectl get pods -n kube-system
kubectl get svc,kubectl get ingress,kubectl get configmap,secrets --all-namespaces

# 2. Check for pending/failed resources
kubectl get pods --field-selector=status.phase=Pending -o wide
kubectl get events --sort-by=.lastTimestamp | tail -50

# 3. Resource monitoring
watch -n 5 'kubectl top nodes'
watch -n 5 'kubectl top pods --all-namespaces'

# 4. Recent cluster activity
kubectl get events -A --sort-by='.lastTimestamp' | tail -100

Emergency Commands

# Force delete a stuck pod
kubectl delete pod <pod-name> -f --grace-period=0

# Evict all pods from a node (force drain)
kubectl drain <node-name> --ignore-daemonsets \
    --delete-emptydir-data --force --grace-period=0

# Restore from backup
kubectl apply -f backup-20260921-143022.yaml

Summary

CategoryKey CommandsPurpose
Resource Managementget, describe, apply, deleteCRUD operations on all resource types
Pod Operationsexec, logs, port-forward, restartDebug and interact with running containers
Deployment Opsrollout history, rollback, scaleManage application lifecycle
Networkingsvc, ingress, port-forward, proxyService discovery and access
Storagepv, pvc, describe pvVolume management
RBACget role,rolebinding, create roleAccess control management
Monitoringtop nodes/pods, eventsResource and health monitoring
Troubleshootingdescribe, logs, exec, restartDebug pod/service failures

References


Report generated for cybersecurity market intelligence purposes. All commands verified against official Kubernetes documentation and cloud provider best practices.

Leave a Reply