Skip to content

Instantly share code, notes, and snippets.

@guiocavalcanti
Created November 9, 2016 17:02
Show Gist options
  • Save guiocavalcanti/ae41866098a634096b08f3ce694d4513 to your computer and use it in GitHub Desktop.
Save guiocavalcanti/ae41866098a634096b08f3ce694d4513 to your computer and use it in GitHub Desktop.

Download and access the cluster

The linux kubectl binary can be fetched with a command like:

  curl -O https://storage.googleapis.com/kubernetes-release/release/v1.4.5/bin/linux/amd64/kubectl

On an OS X workstation, replace linux in the URL above with darwin:

  curl -O https://storage.googleapis.com/kubernetes-release/release/v1.4.5/bin/darwin/amd64/kubectl

After downloading the binary, ensure it is executable and move it into your PATH:

  chmod +x kubectl
  mv kubectl /usr/local/bin/kubectl
export KUBECONFIG=$(pwd)/kubeconfig

Before all

Pro tip: alias k="kubectl"

Namespace

The first step is to createn an environment with your name

  1. Edit namespace/namespace-with-my-name.yml with you name
  2. kubectl create namespace/namespace-with-my-name.yml
  3. Edit kubeconfig with the new namespace
  4. Explain get command (kubectl get namespaces)

Deployment

  1. Show images/whoami and test is docker run -p 8000:8000 guiocavalcanti/whoami:0.0.1
  2. Open deployments/whoami.yml and see the labels and port
  3. kubectl create -f deployment/whoami.yml
  4. Explain describe command (kubectl describe deployments)
  5. Show pods with labels kubectl get pods
  6. Show how to introspect one pod with kubectl port-forward pod-name 8000:8000
  7. Show how to introspect one pod with kubectl exec -it pod-name sh

Service

  1. Scale whoami with kubectl scale deployment whoami --replicas=3
  2. Open service/whoami.yml and show selectors
  3. Create service kubectl create -f service/whoami.yml

Service discovery and internal loadbalancing

  1. Create a new pod to inspect kubectl run -i -t inspector --image=guiocavalcanti/inspector:0.0.1 --restart=Never --rm bash
  2. nslookup whoami
  3. curl whoami
  4. while true; do curl whoami; echo ; done

External service

  1. Open service/whoami-external.yml and show the selectors
  2. kubectl create -f service/whoami-external.yml
  3. kubectl get svc
  4. kubectl describe svc whoami-external

Assignment

  1. Modify your paulo-marlon application container to return "marlon (replica: HOSTNAME)" where HOSTNAME is an environment variable
  2. Deploy a two-tier application with:
  • a HTTP server as front-end
  • the modified paulo-marlon application as backend

Requirements:

  • The HTTP server front-end and the backend shoukd scale independently
  • The HTTP servcer should be accessble to the Web using an ELB (type: Loadbalancer)
  • Both tiers should be fault tolerant (ie. you should be able to delete pods without failing the application)

Tips:

  • If you didn't finished the last assignment you can use images/whoami (40 mb) as base image and nginx:stable-alpine (17 mb)
  • If you can't create an external service (type: LoadBalancer). Use kubectl proxy to reach your service.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment