Skip to content

Instantly share code, notes, and snippets.

@thiagomatar
Last active April 13, 2020 13:36
Show Gist options
  • Save thiagomatar/2ed197e589154dec60b643b9b67c5474 to your computer and use it in GitHub Desktop.
Save thiagomatar/2ed197e589154dec60b643b9b67c5474 to your computer and use it in GitHub Desktop.
Kubernetes Cheat Sheet

Following the kubernets cheat sheets, including minikube, kubectl and definition files

To show nodes

kubectl get nodesfa

To create a pod with nginx image

kubectl run nginx --image=nginx

To show pods

kubectl get pods

To describe pods

kubectl describe pods

To describe specific pod

kubectl describe pod pod-name

To show pods to show additional fields in pods

kubectl get pods -o wide

To create a POD with a file configuration

kubectl create -f pod-definition.yml

To see replication controller created

kubectl get replicationcontroller

To list replicaset that was created

kubectl get replicaset

Describe replica set

kubectl describe replicasets
kubectl describe replicaset replicaset_name

To replace or update yml

kubectl replace -f rs-definition.yml

To scale pods

kubectl scale --replicas=6 -f rs-definition.yml
kubectl scale --replicas=6 replicaset myapp

To delete replicaset

kubectl delete replicaset myapp

To get all objects in kubernetes

kubectl get all

To get deployments

kubectl get deployments

To describe deployments

kubectl describe deployments

To get status of rollout deployment

kubectl rollout status deployment/myapp-deployment

To get history of rollouts

kubectl rollout history deployment/myapp-deployment

To upgrade deployment - new rollout will be created

kubectl apply -f deployment-definition.yml

To upgrade image from deployment definition. Be careful with this command

kubectl set image deployment/myapp-deployment \ nginx:

To rollback upgrade

kubectl rollout undo deployment/myapp-deployment 

To list namespaces

kubectl get ns 

To describe namespaces

kubectl describe ns 

To show namespaces in yaml file

kubectl get ns default -o yaml  

To initialize minikube cluster

minikube start

To stop minikube

minikube stop

Delete the local Minikube cluster:

minikube delete

To add nodes to minikube cluster

minikube node add

To create service

kubectl create -f service-definition.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
labels:
app: myapp
type: front-end
spec:
template:
metadata: # The data about the objects
name: myapp-pod
labels:
app: myapp
type: front-end
spec: # This is additional information to kubernetes
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
app: myapp
apiVersion: v1 # The version of Kubernetes API to using to create objects
kind: Pod # The type of object that will be create
metadata: # The data about the objects
name: myapp-pod
labels:
app: myapp
type: front-end
spec: # This is additional information to kubernetes
containers:
- name: nginx-container
image: nginx
# deprecated prefer use replicaset instead
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc
labels:
app: myapp
type: frontend
spec:
template:
metadata: # The data about the objects
name: myapp-pod
labels:
app: myapp
type: front-end
spec: # This is additional information to kubernetes
containers:
- name: nginx-container
image: nginx
replicas: 3
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp
spec:
template:
metadata: # The data about the objects
name: myapp-pod
labels:
app: myapp
type: front-end
spec: # This is additional information to kubernetes
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
type: front-end
apiVersion: v1
kind: Service
metadata:
name: myapp-services
spec:
type: NodePort
ports:
- targetPort: 80
port: 80
nodePort: 30008
selector:
app: myapp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment