0% found this document useful (0 votes)
76 views

Kubernetes Cheatsheet: Kubectl

This document provides a cheatsheet for common commands used with Kubernetes, Minikube, and Kops. It includes commands for getting and managing Kubernetes resources like pods, deployments, and secrets with kubectl. It also includes commands for starting and configuring local Kubernetes clusters with Minikube and creating and managing Kubernetes clusters on AWS with Kops.

Uploaded by

Sakis Athanasiou
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views

Kubernetes Cheatsheet: Kubectl

This document provides a cheatsheet for common commands used with Kubernetes, Minikube, and Kops. It includes commands for getting and managing Kubernetes resources like pods, deployments, and secrets with kubectl. It also includes commands for starting and configuring local Kubernetes clusters with Minikube and creating and managing Kubernetes clusters on AWS with Kops.

Uploaded by

Sakis Athanasiou
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Kubernetes Cheatsheet

kubectl
kubectl get all
kubectl get pods
kubectl get pods -w // Watch for changes
kubectl get pods -A // All namespaces
kubectl get pods -o wide // Wide output
kubectl get services -n kube-system // Only for specific namespace
kubectl get replicasets
kubectl get deployments
kubectl delete deployments --all
kubectl get pv
kubectl get pvc
kubectl get nodes
kubectl get secrets
kubectl get hpa
kubectl describe secrets/mysecret
kubectl get secret mysecret -o yaml // Output this secret in yaml
kubectl top pods // View the resource consumption for pods
(requires metrics-server)
kubectl top nodes // View the aggregated resource
consumption for nodes (requires metrics-server)
kubectl autoscale deployment api-gateway --cpu-percent 400 --min 1 --max 5 // HPA or
Horizontal Pod Autoscaler (cpu-percent is relevant to requested)
kubectl get hpa api-gateway -o yaml // Output this hpa in yaml so that you can save and reuse
kubectl get roles
kubectl get rolebindings
kubectl create ns playground
kubectl config view // View kubeconfig settings
kubectl get configmaps
kubectl get ingress

minikube
minikube start --cpus 4 --memory 8Gi
minikube stop
minikube delete
minikube ip

minikube addons
minikube addons list // Get the list of minikube add-ons
minikube addons enable metrics-server // Enable metrics-server for kubectl metrics via
‘top’ command
minikube addons enable dashboard // Enable GUI dashboard
minikube dashboard // Run dashboard easily

kops
brew install awscli // Install aws cli tool
brew install kops // Install k8s operations tool
aws configure // Use your new access and secret key here
aws iam list-users // You should see a list of all your IAM users here

// Because "aws configure" doesn't export these vars for kops to use, we export them now
export AWS_ACCESS_KEY_ID=$(aws configure get aws_access_key_id)
export AWS_SECRET_ACCESS_KEY=$(aws configure get aws_secret_access_key)

// Create bucket and enable versioning


aws s3api create-bucket --bucket k8s-test-state-store --region us-east-2 --create-bucket-
configuration LocationConstraint=us-east-2
aws s3api put-bucket-versioning --bucket k8s-test-state-store --versioning-configuration
Status=Enabled

// Prepare local environment


export NAME=test.k8s.local
export KOPS_STATE_STORE=s3://test.k8s.local

// Discover which availability zones are available to us in the region


aws ec2 describe-availability-zones --region us-west-2

// Create SSH key pair for kops, if not already created


ssh-keygen -t rsa -b 4096 -f ~/.ssh/kops -v

// Create cluster files


kops create cluster --zones us-west-2a,us-west-2b,us-west-2c,us-west-2d --master-count=1
--master-size t2.medium --node-count=2 --node-size=t2.medium --name=${NAME}

// SSH public key must be specified when running with AWS


kops create secret --name ${NAME} sshpublickey admin -i ~/.ssh/kops.pub

// Get or customize cluster configuration (optional)


kops get cluster
kops edit cluster --name ${NAME}

// Get or customize InstanceGroup configuration (optional)


kops get ig --name ${NAME}
kops edit ig master-us-west-2a --name ${NAME}
kops edit ig nodes --name ${NAME}
kops update cluster --name ${NAME} --yes // Build the actual cluster
kops validate cluster // Validate cluster
kops delete cluster --name ${NAME} --yes // Delete cluster

helm
brew install helm
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm repo update
helm install monitoring stable/prometheus-operator
kubectl service/monitoring-prometheus-oper-prometheus // change type to LoadBalancer

You might also like