Giter Club home page Giter Club logo

kubernetes-cheatsheet's Introduction

A Kubernetes cheatsheet

Setting up local environment on MacOS

Install an hypervisor (Such as virtualbox) Install kubectl (kubernetes-cli)

# Install kubectl
brew install kubernetes-cli

# Verify
kubectl version

Install minikube

# Install minikube
brew cask install minikube

General information

# Get cluster info
kubectl cluster-info

# Get nodes info
kubectl get nodes

# Get pod info
kubectl get pods

# Get services
kubectl get services

# Get deployments
kubectl get deployments

# Detailed info
kubectl describe nodes

# Print pod logs
kubectl logs $POD_NAME

# Run a command on a container inside a pod
kubectl exec $POD_NAME echo 'hello from inside the pod!'

# Open a bash inside the pod
kubectl exec -ti $POD_NAME bash

# Append -help to get more info on the command
kubectl get nodes --help

Starting a cluster

# Start minikube
minikube start

Deploy to a cluster

# Check that the cluster is available
# The output should return both a master and a client
kubectl version

# Create a new deployment
# Notes
# a)Images hosted outside of dockerhub should be specified
# with full url
kubectl run deploy-name  
  --image=gcr.io/google-samples/kubernetes-bootcamp:v1
  --port=8080

# In a separate terminal, create a proxy to enable
# communication with the clusters
kubectl proxy

Services commands

# Expose the port on a deployment to external traffic and
# create a service
# Check the Using source IP link for more info on types
kubectl expose deployment/kubernetes-bootcamp
  --type="NodePort"
  --port 8080

# Removes a service
kubectl delete service -l run=kubernetes-bootcamp

Label your pods

# Label a pod with APP = v1
kubectl label pod $POD_NAME app=v1

# Fetch pods by label
kubectl get pods -l app=v1

Scale

Default deployment name is kubernetes-bootcamp

# Check deployment state
# DESIRED: Desired number of replicas
# CURRENT: Current number of replicas
# UP-TO-DATE: Replicas matching the current desired state
# AVAILABLE: Replicas available to users
kubectl get deployments

# Set the desired replica states for a deployment
# Scaling up
kubectl scale deployments/kubernetes-bootcamp --replicas=4

# Scaling down
kubectl scale deployments/kubernetes-bootcamp --replicas=2

# Verify deployments again to check the current state
kubectl get deployments

# Check number of pods that changed
kubectl get pods -o wide

# Check changes made to pods
kubectl describe deployments/kubernetes-bootcamp

Cluster API commands

locahost:8001 is the url of the cluster api

# Export the pod name to a environment variable
# go-template is how the output will be formated with Go
export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')

# Make a request to the api
curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy/

# Test exposed app connection
curl $(minikube ip):$NODE_PORT

Resources and quick links

kubernetes-cheatsheet's People

Contributors

cesargralmeida avatar

Stargazers

Bruno Arakaki avatar

Watchers

 avatar

Forkers

savadev

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.