Coder Social home page Coder Social logo

nicholasjhenry / kubernetes-playground Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 5 KB

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.

Home Page: https://kubernetes.io

Makefile 100.00%
kubernetes professional-development

kubernetes-playground's Introduction

Kubernetes Playground

Setup

  1. Install Docker for Mac (Edge)
  2. Enable Kubernetes (context: docker-desktop)
  3. Run the following Make target

make dev.setup

Tools

  • kubectl
  • kubectx

Commands

Mostly based on https://kubernetes.io/docs/tutorials/kubernetes-basics/:

# 1. Create a cluster (via Desktop Docker, Minikube, DigitalOcean)
doctl account get
kubectl version
kubectl config get-contexts
kubectl config use-context docker-desktop # or kubectx
# cluster details
kubectl cluster-info
kubectl get nodes

# 2. Deploy an app (normally handled by a configuration file)
kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1
kubectl get deployments
kubectl proxy
curl http://localhost:8001/version

# 3. Viewing Pods and Nodes
# Step 1: Check application configuration
kubectl get pods
kubectl describe pods
# Step 2: Show the app in the terminal
export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME # cannot do /proxy on `docker-desktop`
# Step 3: View the container logs
kubectl logs $POD_NAME
# Step 4: Executing command on the container
kubectl exec $POD_NAME env
kubectl exec -ti $POD_NAME bash
cat server.js
curl localhost:8080

# 4. Exposing Your App
# Step 1: Create a new service
kubectl get services
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080 # LoadBalancer not available
kubectl get services
kubectl describe services/kubernetes-bootcamp
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}') # port exposed
curl localhost:$NODE_PORT
# Step 2: Using labels
kubectl describe deployment
kubectl get pods -l app=kubernetes-bootcamp
kubectl get services -l app=kubernetes-bootcamp
export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
kubectl label pod $POD_NAME version=v1
kubectl describe pods $POD_NAME
kubectl get pods -l app=v1
# Step 3: Deleting a service
kubectl delete service -l app=kubernetes-bootcamp
kubectl get services
curl localhost:$NODE_PORT # fail
kubectl exec -ti $POD_NAME curl localhost:8080 # still running internally

# 5. Scale up your app
# Step 1: Scaling a deployment
kubectl get deployments
kubectl get rs
kubectl scale deployments/kubernetes-bootcamp --replicas=4
kubectl get deployments
kubectl get pods -o wide
kubectl describe deployments/kubernetes-bootcamp
# Step 2: Load Balancing
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
kubectl describe services/kubernetes-bootcamp
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}') && echo NODE_PORT=$NODE_PORT
curl localhost:$NODE_PORT # repeat to see the different pod
# Step 3: Scale Down
kubectl scale deployments/kubernetes-bootcamp --replicas=2
kubectl get deployments
kubectl get pods -o wide

# 6. Update the version of the app
# Step 1: Update the version of the app
kubectl scale deployments/kubernetes-bootcamp --replicas=4
kubectl get deployments
kubectl get pods
kubectl describe pods # current image version
kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
# Step 2: Verify an update
kubectl describe services/kubernetes-bootcamp
export NODE_PORT=$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}') && echo NODE_PORT=$NODE_PORT
curl localhost:$NODE_PORT
kubectl rollout status deployments/kubernetes-bootcamp
kubectl describe pods | grep Image
# Step 3: Rollback an update
kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=gcr.io/google-samples/kubernetes-bootcamp:v10
kubectl get pods # v10 does not exist
kubectl describe pods # for more info
kubectl rollout undo deployments/kubernetes-bootcamp
kubectl get pods
kubectl describe pods

# Cleanup
kubectl delete deployment,service kubernetes-bootcamp

Other helpful commands

kubectl get events
kubectl config view
kubectl port-forward hello-3015430129-g95j6 8080

Definitions

Kubernetes automates the distribution and scheduling of application containers across a cluster in a more efficient way.

Term Definition
application
application instance a process for a running application container
cluster a group of computers to work as a single unit
container
container runtime Examples: Docker, rkt
application container an application deploy in a container to a cluster (containerized application)
deployment a manifest describing how to create and update containerized applications to run on individual nodes inside a pod, optionally via a service
deployment controller a monitoring process in the master resource for a deployment
label Example: app: foo
LabelSelector a selector for a label
kubelet an agent for a node resource communicating with a master resource of the cluster.
master (resource) a co-ordinator resource
node (resource) a worker resource (VM or physical machine) with a container runtime
pod a host for application instances of one or more application containers and shared resources accessible via an IP address
pod lifecycle
replica a duplicated set of pods to scale an application
ReplicaSet
resource
rolling update an update with zero downtime by incrementally updating pods
selector
service a logical set of pods (deployment) and a policy by which to access them determined by a LabelSelector
ServiceSpec a configuration for a service
shared resource Examples: shared storage or volume, networking, shared configuration
type a field in a ServiceSpec. Examples: ClusterIP, NodePort, LoadBalancer, ExternalName

kubernetes-playground's People

Contributors

nicholasjhenry avatar

Watchers

 avatar

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.