60
1 kubectl Introduction For Console Hackers TUT-1153

kubectl Introduction For Console Hackers

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: kubectl Introduction For Console Hackers

1

kubectl Introduction For Console Hackers

TUT-1153

Page 2: kubectl Introduction For Console Hackers

2

Lucas Bickel

Developer @ Adfinis

OSS wizard by night

[email protected]

twitter.com/hairmare

Page 3: kubectl Introduction For Console Hackers

3

Since 2000

Berne, Basel, Zürich, Lausanne & Netherlands

Over 65 employees

100% Open Source

Broad customer base

About Adfinis

Page 4: kubectl Introduction For Console Hackers

4

EngineeringManaged Services

DevOps Development

Our Services

Page 5: kubectl Introduction For Console Hackers

5

kubectl

Page 6: kubectl Introduction For Console Hackers

6

● Kubernetes is the de-facto API to interact with

cloudy container based infrastructure like the

SUSE CaaS Platform

● We need a tool to drive the API

● Kubernetes has kubectl as default client

● We will be showing you how kubectl works and

what it can do

Page 7: kubectl Introduction For Console Hackers

7

Kube-Control? Kube-CeeTeeEl? Koob-Cattle?

Personally we like Kube-Cuddle because it sounds

fluffy like the clouds we are deploying to

kubectl

Page 8: kubectl Introduction For Console Hackers

8

kubectl cf

Low-level Kubernetes client High-level CloudFoundry client

Can manage a plethora of aspects

of a k8s cluster

Mostly deploys code, very

opinionated, not many options

Needs some time to master it Quite easy to learn

While Kubernetes users mostly use kubectl the users

of Cloud Foundry based solutions rely on cf

kubectl vs. cf

Page 9: kubectl Introduction For Console Hackers

9

How do you pronounce kubectl?

● kube-CeeTeeEll

● kube-cuddle

● Kube-Control

● magical yaml generator tool

Quiz Time!

Page 10: kubectl Introduction For Console Hackers

10

How do you pronounce kubectl?

● kube-CeeTeeEll

● kube-cuddle

● Kube-Control

● magical yaml generator tool

Quiz Time!

Page 11: kubectl Introduction For Console Hackers

11

How does the Client interact with the API Server?

● SOAP

● REST (JSON or protobuf)

● XML-RPC

● SMTP

Quiz Time!

Page 12: kubectl Introduction For Console Hackers

12

How does the Client interact with the API Server?

● SOAP

● REST (JSON or protobuf)

● XML-RPC

● SMTP

Quiz Time!

Page 13: kubectl Introduction For Console Hackers

13

auth

Page 14: kubectl Introduction For Console Hackers

14

Users are assumed to be managed by an outside,

independent service

● an admin distributing private keys

● a user store like Keystone or Google Accounts

● or a file with a list of usernames and passwords

Page 15: kubectl Introduction For Console Hackers

15

Run any command to login to your cluster

Depending on the authentication mechanism it will do the right thing™

We like using kubectl cluster-info to log on to a cluster

kubectl Auth

Page 16: kubectl Introduction For Console Hackers

16

Cluster-info

Page 17: kubectl Introduction For Console Hackers

17

Kubernetes master is running at https://caasp-master.susecon.syclou...

KubeDNS is running at https://caasp-master.susecon.sycloud.ch:6443...

To further debug and diagnose cluster problems, use

kubectl cluster-info dump

The dump shows where the API server is running as well as what

components extend the API server (ie. KubeDNS, kubernetes-dashboard)

kubectl Cluster-info

Page 18: kubectl Introduction For Console Hackers

18

● kubectl api-versions

● kubectl api-resources

● kubectl explain pod --recursive=true

A Pod is a group of containers that are deployed together on the same host

Inspecting The API

Page 19: kubectl Introduction For Console Hackers

19

Which of the following are default APIs available in K8s?

● apps/v1

● monitoring.coreos.com/v1

● batch/v1

● rbac.authorization.k8s.io/v1

● service.openstack.io/v1beta9

Quiz Time!

Page 20: kubectl Introduction For Console Hackers

20

Which of the following are default APIs available in K8s?

● apps/v1

● monitoring.coreos.com/v1

● batch/v1

● rbac.authorization.k8s.io/v1

● service.openstack.io/v1beta9

Quiz Time!

Page 21: kubectl Introduction For Console Hackers

21

How do you figure out what the parts of the API do/support?

● stare at it for a long time

● run kubectl explain <resource> --recursive=true

● search for it in the search engine of your choice

● run man kubernetes

Quiz Time!

Page 22: kubectl Introduction For Console Hackers

22

How do you figure out what the parts of the API do/support?

● stare at it for a long time

● run kubectl explain <resource> --recursive=true

● search for it in the search engine of your choice

● run man kubernetes

Quiz Time!

Page 23: kubectl Introduction For Console Hackers

23

resources

Page 24: kubectl Introduction For Console Hackers

24

● kubectl get nodes/pods/services…

● kubectl describe nodes/pods/services… <resource-name>

You can use get and describe to access all in-cluster resources.

Add -oyaml to look at a YAML representation of a resource.

Getting And Describing Resources

Page 25: kubectl Introduction For Console Hackers

25

Add -oyaml to look at a YAML representation of a resource

Kubectl supports a bunch of other output formats

● json

● yaml

● wide

● name

● custom-columns=...

● custom-columns-file=...

● go-template=...

● go-template-file=...

● jsonpath=...

● jsonpath-file=...

Getting And Describing Resources

Page 26: kubectl Introduction For Console Hackers

26

How can you you look up pods?

● kubectl show $POD_NAME

● kubectl render $POD_NAME

● kubectl get $POD_NAME

● kubectl get pod $POD_NAME

Quiz Time!

Page 27: kubectl Introduction For Console Hackers

27

How can you you look up pods?

● kubectl show $POD_NAME

● kubectl render $POD_NAME

● kubectl get $POD_NAME

● kubectl get pod $POD_NAME

Quiz Time!

Page 28: kubectl Introduction For Console Hackers

28

What kind of output does describe display?

● YAML representation of resources

● State of resources with additional infos

● output similar to top

Quiz Time!

Page 29: kubectl Introduction For Console Hackers

29

What kind of output does describe display?

● YAML representation of resources

● State of resources with additional infos

● output similar to top

Quiz Time!

Page 30: kubectl Introduction For Console Hackers

30

Apply

Page 31: kubectl Introduction For Console Hackers

31

● You can create in-cluster resources from a local YAML file

● Let’s assume the following Pod definition

apiVersion: v1

kind: Pod

metadata:

name: potz-pod

spec:

containers:

- name: app-container

image: invalid/image/path

● Run kubectl apply -f pod.yaml

Apply Some YAML

Page 32: kubectl Introduction For Console Hackers

32

Debugging what went wrong:

● kubectl get

● kubectl describe

Debug Issues

Page 33: kubectl Introduction For Console Hackers

33

kubectl edit pod potz-pod

● kubectl is a quick way to edit resources directly in a cluster

● Only use it for debugging

● Kubernetes should not be the source of truth for your cluster config

Edit Resource

Page 34: kubectl Introduction For Console Hackers

34

How can you add resources to your cluster?

● kubectl get

● kubectl apply

● kubectl import

● kubectl load

Quiz Time!

Page 35: kubectl Introduction For Console Hackers

35

How can you add resources to your cluster?

● kubectl get

● kubectl apply

● kubectl import

● kubectl load

Quiz Time!

Page 36: kubectl Introduction For Console Hackers

36

Should you use kubectl edit on production?

● na

● no

● njet

● non

● nein

● geen

● yes

Quiz Time!

Page 37: kubectl Introduction For Console Hackers

37

Should you use kubectl edit on production?

● na

● no

● njet

● non

● nein

● geen

● yes

Quiz Time!

Page 38: kubectl Introduction For Console Hackers

38

Scale

Page 39: kubectl Introduction For Console Hackers

39

● Kubernetes dashboard

● Stratos

kubectl scale --replicas=5

Let’s Have A Look At The Pod

Page 40: kubectl Introduction For Console Hackers

40

What does the replica argument to the scale command specify?

● The number of target replicas

● How many replicas to add

Quiz Time!

Page 41: kubectl Introduction For Console Hackers

41

What does the replica argument to the scale command specify?

● The number of target replicas

● How many replicas to add

Quiz Time!

Page 42: kubectl Introduction For Console Hackers

42

Debug

Page 43: kubectl Introduction For Console Hackers

43

You can look at the stderr/stdout logs of a pod

kubectl logs $POD_NAME

Inspect Logs Of An Application

Page 44: kubectl Introduction For Console Hackers

44

You can run commands (like an interactive shell) inside of a running pod

kubectl exec -ti $POD_NAME sh

Execute Commands

Page 45: kubectl Introduction For Console Hackers

45

If a pod is in a failed state, just delete it and the cluster will recreate it

kubectl delete pod $POD_NAME

Delete Pods

Page 46: kubectl Introduction For Console Hackers

46

What commands can you use to debug the state of your application?

● kubectl logs

● kubectl describe

● kubectl exec

● kubectl y-tho

Quiz Time!

Page 47: kubectl Introduction For Console Hackers

47

What commands can you use to debug the state of your application?

● kubectl logs

● kubectl describe

● kubectl exec

● kubectl y-tho

Quiz Time!

Page 48: kubectl Introduction For Console Hackers

48

Storage

Page 49: kubectl Introduction For Console Hackers

49

We can interact with storage resources using a couple of commands

● kubectl get pv

● kubectl get pvc

● kubectl apply -f pvc.yaml

Let’s look at the disks in SUSE Enterprise Storage (SES)

PersistentVolume And PersistentVolumeClaims

Page 50: kubectl Introduction For Console Hackers

50

You can modify existing resources using kubectl patch

kubectl patch \

pvc $PVC \

-p '{"spec":{"resources":{"requests":{"storage":"10Gi"}}}}'

In this example we are expanding a persistent volume claim to 10Gi of space

by specifying the change as JSON.

Growing Volumes

Page 51: kubectl Introduction For Console Hackers

51

Which commands interact with Kubernetes storage?

● regular commands like kubectl get/patch/describe/edit

● lvchange, mkfs and dd

● special kubectl storage get/patch/edit commands

Quiz Time!

Page 52: kubectl Introduction For Console Hackers

52

Which commands interact with Kubernetes storage?

● regular commands like kubectl get/patch/describe/edit

● lvchange, mkfs and dd

● special kubectl storage get/patch/edit commands

Quiz Time!

Page 53: kubectl Introduction For Console Hackers

53

Helm

Page 54: kubectl Introduction For Console Hackers

54

Helm is the de-facto standard package manager for Kubernetes resources

It directly interacts with the Kubernetes API

What Is Helm

Page 55: kubectl Introduction For Console Hackers

55

We’ll redeploy the Pod from before using Helm

All the parts of the deployment may be found by searching for a label

kubectl get all -l helm.sh/release=$RELEASE_NAME

Note that get all does not actually return all the resources

Deploy With Helm, Inspect With kubectl

Page 56: kubectl Introduction For Console Hackers

56

How do Helm and kubectl differ?

● Helm and kubectl do the same thing but their commands have

different semantics

● kubectl is the native Kubernetes command line client, Helm uses the

Kubernetes API without using kubectl

● Helm drives kubectl to deploy YAML-manifests

● kubectl is a wrapper to run Helm, Helm does the heavy lifting

● Both tools are written in golang

Quiz Time!

Page 57: kubectl Introduction For Console Hackers

57

How do Helm and kubectl differ?

● Helm and kubectl do the same thing but their commands have

different semantics

● kubectl is the native Kubernetes command line client, Helm uses the

Kubernetes API without using kubectl

● Helm drives kubectl to deploy YAML-manifests

● kubectl is a wrapper to run Helm, Helm does the heavy lifting

● Both tools are written in golang

Quiz Time!

Page 58: kubectl Introduction For Console Hackers

58

Tally Time

Page 59: kubectl Introduction For Console Hackers

59

How many questions did you get right?

Tweet us your results to @adfinis using the #SUSEconDigital2020 hashtag.

Page 60: kubectl Introduction For Console Hackers

61

General Disclaimer

This document is not to be construed as a promise by any participating company to develop, deliver, or market a

product. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making

purchasing decisions. SUSE makes no representations or warranties with respect to the contents of this document,

and specifically disclaims any express or implied warranties of merchantability or fitness for any particular

purpose. The development, release, and timing of features or functionality described for SUSE products remains at

the sole discretion of SUSE. Further, SUSE reserves the right to revise this document and to make changes to its

content, at any time, without obligation to notify any person or entity of such revisions or changes. All SUSE marks

referenced in this presentation are trademarks or registered trademarks of SUSE, LLC, Inc. in the United States and

other countries. All third-party trademarks are the property of their respective owners.