Coder Social home page Coder Social logo

kubernetes-hands-on's Introduction

Kubernetes-hands-on

This repo aims to provide a quick hands-on for Kubernetes beginners.

Pre-requisites

  • Google Cloud account
  • Be familiar with Docker

Create your K8s cluster

  • Login to the Google Cloud console
  • Create a new project
  • Browse Kubernetes Engine
  • Create a cluster using the default values
  • Activate the Google Cloud Shell
  • Optional: install extension SSH for Google Cloud Platform

Explore your cluster with kubectl

From Google Cloud Shell, run the following command to get the kube config:

gcloud container clusters get-credentials [CLUSTER-NAME] --zone [ZONE-NAME] --project [PROJECT-NAME]

Notice, the command is automatically generated when pressing the Connect button from the cluster list.

Display your kube config

cat .kube/config

Play with kubectl to explore some Kubernetes resources

list nodes
kubectl get nodes

list services
kubectl get services

list pods
kubectl get pods

list deployment
kubectl get deployment

list replicas set
kubectl get replicasets

list replicas persistent volume
kubectl get persistentvolumes

list namespaces
kubectl get namespace

list secrets
kubectl get secret

Notice, that you can use short-names
kubectl get no
kubectl get svc
kubectl get ns

List everything on your cluster
kubectl get all

Use the describe command to get more details about a specific resource
kubectl describe node <node-name>

Deploy an app

Deploy a simple app

kubectl run hello-server --image gcr.io/google-samples/hello-app:1.0 --port 8080

Add a load balancer in front

kubectl expose deployment hello-server --type "LoadBalancer"

Fetch the public IP assigned to the Loadbalancer, notice it might take some time:

kubectl expose deployment hello-server --type "LoadBalancer"

Browse the service.

curl http://<ip>:8080/

Get the logs
kubectl logs deploy/hello-server -f

Scale

Scale up your deployment
kubectl scale deploy/hello-server --replicas 3

Run the cURL command multiple time and attention that the hostname change, as the traffic get load balanced accross your nodes.
curl http://<ip>:8080/

Watch the pods by runnig this comamand in another Shell
kubectl get pods -w

In another Google Shell windows, kill one pods
kubectl delete pod <pod-name>

Notice that the pod get recreated!

Destroy one VM

Browse the VM instance service Delete on VM from your worker pool

Watch the pods and the pods beeing automatically recreated, run the commands in separated Shell
kubectl get pods -w
kubectl get nodes -w

Delete cluster

gcloud container clusters delete [CLUSTER_NAME] --zone [ZONE-NAME] --project [PROJECT-NAME]

References

kubernetes-hands-on's People

Contributors

benfab 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.