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

Kubernets CommandCheastsheet

This document provides examples of commands for interacting with a Kubernetes cluster using kubectl including: - Getting information on nodes, pods, services, versions and cluster configuration - Managing pods, replication controllers, and services - Scaling replication controllers - Mapping ports for services - Deleting pods, replication controllers, and services - Draining and deleting nodes - Executing commands on pods and getting logs - Initializing and joining nodes to a Kubernetes cluster - Creating and deleting namespaces and secrets

Uploaded by

sundar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
157 views

Kubernets CommandCheastsheet

This document provides examples of commands for interacting with a Kubernetes cluster using kubectl including: - Getting information on nodes, pods, services, versions and cluster configuration - Managing pods, replication controllers, and services - Scaling replication controllers - Mapping ports for services - Deleting pods, replication controllers, and services - Draining and deleting nodes - Executing commands on pods and getting logs - Initializing and joining nodes to a Kubernetes cluster - Creating and deleting namespaces and secrets

Uploaded by

sundar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

kubectl get services # List all services

kubectl get pods # List all pods


kubectl get nodes -w # Watch nodes continuously
kubectl version # Get version information
kubectl cluster-info # Get cluster information
kubectl config view # Get the configuration
kubectl describe node <node> # Output information about a node
kubectl get pods # List the current pods
kubectl describe pod <name> # Describe pod <name>
kubectl get rc # List the replication controllers
kubectl get rc --namespace="<namespace>" # List the replication controllers in
<namespace>
kubectl describe rc <name> # Describe replication controller <name>
kubectl get svc # List the services
kubectl describe svc <name> # Describe service <name>

kubectl run <name> --image=<image-name> # Launch a pod


called <name>
# using image
<image-name>
kubectl create -f <manifest.yaml> # Create a
service described
# in
<manifest.yaml>
kubectl scale --replicas=<count> rc <name> # Scale
replication controller
# <name> to
<count> instances
kubectl expose rc <name> --port=<external> --target-port=<internal> # Map port
<external> to
# port
<internal> on replication
# controller
<name>
kubectl delete pod <name> # Delete pod
<name>
kubectl delete rc <name> # Delete
replication controller <name>
kubectl delete svc <name> # Delete service
<name>
kubectl drain <n> --delete-local-data --force --ignore-daemonsets # Stop all pods
on <n>
kubectl delete node <name> # Remove <node>
from the cluster
kubectl exec <service> <command> [-c <$container>] # execute <command> on
<service>, optionally
# selecting container
<$container>
kubectl logs -f <name> [-c <$container>] # Get logs from service <name>,
optionally
# selecting container
<$container>
watch -n 2 cat /var/log/kublet.log # Watch the Kublet logs
kubectl top node # Show metrics for nodes
kubectl top pod # Show metrics for pods
kubeadm init # Initialize your master
node
kubeadm join --token <token> <master-ip>:<master-port> # Join a node to your
Kubernetes cluster
kubectl create namespace <namespace> # Create namespace <name>
kubectl taint nodes --all node-role.kubernetes.io/master- # Allow Kubernetes master
nodes to run pods
kubeadm reset # Reset current state
kubectl get secrets # List all secrets

============================ cluster =====================================

# start up a cluster
KUBERNETES_PROVIDER=vagrant ./cluster/kube-up.sh

# start a simple vagrant cluster


NUM_NODES=1 KUBERNETES_PROVIDER=vagrant KUBE_ENABLE_CLUSTER_MONITORING=none
KUBE_ENABLE_CLUSTER_UI=false ./cluster/kube-up.sh

# validate cluster
./cluster/validate-cluster.sh
kubectl cluster-info

# delete all rc & svc


kubectl delete svc,rc --all
kubectl delete $(kubectl get rc,svc -o name)

# watch for events


kubectl get ev -w

# schema / avaiable fields for rc/pods/svc ...


https://github.com/kubernetes/kubernetes/blob/master/pkg/api/types.go

# a simple service
https://github.com/kubernetes/kubernetes/blob/master/docs/user-
guide/walkthrough/service.yaml

# available signals for a pod


https://github.com/luebken/httplog/blob/signals/rc.yml

# debug
kubectl logs --previous <pod>

# start a simple container


kubectl run busybox --image=busybox

# get system services


kubectl get svc --all-namespaces

# a debug container
kubectl run curlpod --image=radial/busyboxplus:curl --command -- /bin/sh -c "while
true; do echo hi; sleep 10; done"
kubectl exec -it curlpod-5f0mh nslookup redis

# upload files
kubectl exec -i ghost-deployment-1955090760-zivlz -- /bin/bash -c 'cat >
/tmp/testmail.msg' < testmail.msg

# more debug
http://kubernetes.io/v1.1/docs/user-guide/debugging-services.html

# create a new config


PROJECT_ID='mdl-k8s'
CLUSTER='cluster-4'
CLUSTER_ZONE='europe-west1-c'

gcloud config set project $PROJECT_ID


gcloud config set container/cluster $CLUSTER
gcloud config set compute/zone $CLUSTER_ZONE
gcloud container clusters get-credentials $CLUSTER

kubectl config use-context gke_${PROJECT_ID}_${CLUSTER_ZONE}_${CLUSTER}

You might also like