Skip to content

Instantly share code, notes, and snippets.

@mhausenblas
Last active November 8, 2018 13:15
Show Gist options
  • Save mhausenblas/5a44b47f3d412dd57c7a55549e537824 to your computer and use it in GitHub Desktop.
Save mhausenblas/5a44b47f3d412dd57c7a55549e537824 to your computer and use it in GitHub Desktop.
Hands-on exercises for the "Introduction to Kubernetes" session

An Introduction to Kubernetes

Also, check out this kubectl cheatsheet.

Basics

Using Katacoda online or install Minikube locally.

Get an overview of all pods across all namespaces:

$ kubectl get pods --all-namespaces

Launch a simple one-shot pod:

$ kubectl run -it --rm oneshot --restart=Never --image=quay.io/mhausenblas/jump:0.2 -- sh

Launch long-running process (NGINX):

$ kubectl create ns dev

$ kubectl -n dev run webserver --image=nginx:1.13

Scale the webserver deployment to 2 replicas:

$ kubectl -n dev scale deploy/webserver --replicas=2

Create a service webserver for the deployment and check it:

$ kubectl -n dev expose deployment webserver --port=80 --target-port=80

$ kubectl -n dev describe svc -l=run=webserver

List all resources we created:

$ kubectl -n dev get po,rs,deploy,svc

Query the webserver service from within the cluster (from the default namespace):

$ kubectl run -it --rm curlpod --restart=Never --image=quay.io/mhausenblas/jump:0.2 -- curl webserver.dev

End-to-end example app

Vanilla Kubernetes

Using Katacoda online or install Minikube locally.

$ git clone https://github.com/kubernauts/dok-example-us.git && cd dok-example-us

$ kubectl create namespace dok

$ kubectl -n=dok apply -f stock-gen/app.yaml 
$ kubectl -n=dok apply -f stock-con/app.yaml 

$ kubectl -n=dok run -i -t --rm curlpod --restart=Never --image=quay.io/mhausenblas/jump:0.2 -- curl stock-gen:9999/stockdata
$ kubectl -n=dok run -i -t --rm curlpod --restart=Never --image=quay.io/mhausenblas/jump:0.2 -- curl stock-con/average/NYSE:RHT

Using S2I with OpenShift

Using Katacoda

$ oc new-project dok-test

$ oc new-app --docker-image=quay.io/mhausenblas/stock-gen:0.3 \
           --name=stock-gen \
           --env=DOK_STOCKGEN_PORT=9999 \
           --env=DOK_STOCKGEN_CRASHEPOCH=100

$ oc expose dc/stock-gen --port=9999

$ oc new-app https://github.com/kubernauts/dok-example-us \
           --strategy=source \
           --name=stock-con \
           --context-dir=stock-con \
           --env=DOK_STOCKGEN_HOSTNAME=stock-gen \
           --env=DOK_STOCKGEN_PORT=9999

$ oc patch svc stock-con \
   --type=merge \
   --patch='{"spec": {"ports": [ { "name": "http", "port": 9898, "protocol": "TCP", "targetPort": 9898 } ] } }'

$ oc expose svc stock-con --port=9898

$ oc get po,dc,svc,routes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment