55
Container Orchestration with Kubernetes Open Source Summit Europe October 26, 2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 Systems GmbH [email protected]

OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

  • Upload
    vanminh

  • View
    222

  • Download
    0

Embed Size (px)

Citation preview

Page 1: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Container Orchestration with KubernetesOpen Source Summit Europe October 26, 2017

Michael SteinfurthLinux/Unix Consultant & Trainer

B1 Systems [email protected]

Page 2: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Introducing B1 Systemsfounded in 2004operating both nationally and internationallyabout 100 employeesvendor-independent (hardware and software)focus:

consultingsupportdevelopmenttrainingoperationssolutions

offices in Rockolding, Berlin, Cologne & Dresden

B1 Systems GmbH Container Orchestration with Kubernetes 2 / 55

Page 3: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Areas of Expertise

B1 Systems GmbH Container Orchestration with Kubernetes 3 / 55

Page 4: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Workshop Setup

B1 Systems GmbH Container Orchestration with Kubernetes 4 / 55

Page 5: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Host Setup

three nodesrecommended CentOS 7 with extra and updates repomake hostnames resolvable on all hosts (dns, hosts file)share ssh keys between all hosts

B1 Systems GmbH Container Orchestration with Kubernetes 5 / 55

Page 6: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Software Components

etcd cluster – key value storeflanneld – overlay networkdocker – container enginekubernetes packages

B1 Systems GmbH Container Orchestration with Kubernetes 6 / 55

Page 7: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

etcd Cluster

necessary for Kubernetes, flanneldpart of the coreos projectdistributed key value storehigh availability is necessaryquorum majority needed

↪→ run on odd number of DCs (minimum 3)

B1 Systems GmbH Container Orchestration with Kubernetes 7 / 55

Page 8: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Overlay Network – flanneld

containers need to communicate on multiple nodesmultiple solutions

flannel, weave plugin, opencontrail

flannel integrates most easily + quite good performancepart of the coreos projectflanneld on each worker node

B1 Systems GmbH Container Orchestration with Kubernetes 8 / 55

Page 9: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Kubernetes

Kubernetes master and workermaster component = management plane

schedules, supervises replicates podssaves configuration data, manages volumesAPI interface

worker component connects to container backendcreates real containercreates service connections (iptables)container image handling

B1 Systems GmbH Container Orchestration with Kubernetes 9 / 55

Page 10: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Installation & Configuration

B1 Systems GmbH Container Orchestration with Kubernetes 10 / 55

Page 11: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Packages to Install

Install packages, run command on each node# yum install etcd etcdctl flannel \kubernetes-master kubernetes-node kubernetes-client

B1 Systems GmbH Container Orchestration with Kubernetes 11 / 55

Page 12: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

etc configuration on each /etc/etcd/etcd.conf (adapt HOSTNAME: node1 )# [member]ETCD_DATA_DIR="/var/lib/etcd/"ETCD_NAME="node1"ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"ETCD_ADVERTISE_CLIENT_URLS="http://node1:2379"

# discoveryETCD_INITIAL_CLUSTER="node1=http://node1:2380,node2=http://node2:2380,\node3=http://node3:2380"ETCD_INITIAL_CLUSTER_TOKEN="etcd-token"ETCD_INITIAL_ADVERTISE_PEER_URLS="http://node1:2380"ETCD_INITIAL_CLUSTER_STATE="new"

B1 Systems GmbH Container Orchestration with Kubernetes 12 / 55

Page 13: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

etcd Cluster Start and Check

1 Start etcd on each node quickly one after the other:

# systemctl start etcd

2 Check cluster state on one node:

# etcdctl cluster-health

B1 Systems GmbH Container Orchestration with Kubernetes 13 / 55

Page 14: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

flannel Configuration

Set basic flannel configuration as key in etcd:

# etcdctl set /network/config \’{ "Network": "172.16.0.0/16", "Backend": { "type": "host-gw"} }’

Edit /etc/sysconfig/flanneld on each node (adapt hostnames):

FLANNEL_ETCD_ENDPOINTS="http://node1:2379,http://node2:2379,\http://node3:2379"FLANNEL_ETCD_KEY="/network"

B1 Systems GmbH Container Orchestration with Kubernetes 14 / 55

Page 15: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

flanneld Start and Check

1 Start flanneld on each node:

# systemctl start flanneld

2 Check if flanneld is running:

# systemctl is-active flanneld# ip route show

B1 Systems GmbH Container Orchestration with Kubernetes 15 / 55

Page 16: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Kubernetes Master apiserver

1 Remove service account2 Add etcd cluster3 NodePort range for external access ports to applications ports4 Set service-cluster-ip-range

B1 Systems GmbH Container Orchestration with Kubernetes 16 / 55

Page 17: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Edit /etc/kubernetes/apiserver on node1KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"KUBE_API_PORT="--insecure-port=8080"KUBELET_PORT="--kubelet-port=10250"KUBE_ETCD_SERVERS="--etcd-servers=http://node1:2379,http://node2:2370,\http://node3:2379"KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=172.18.0.0/16"

#just remove "ServiceAccount"KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,\NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"KUBE_API_ARGS=""

B1 Systems GmbH Container Orchestration with Kubernetes 17 / 55

Page 18: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Kubernetes Master scheduler + controller-manager

/etc/kubernetes/controller-managerKUBE_CONTROLLER_MANAGER_ARGS=""

/etc/kubernetes/schedulerKUBE_SCHEDULER_ARGS=""

B1 Systems GmbH Container Orchestration with Kubernetes 18 / 55

Page 19: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Kubernetes Master Start and Check

1 Start master components on node1:

# systemctl start kube-apiserver kube-controller-manager kube-scheduler

2 Check if all are running on node1:

# systemctl is-active "kube*"# kubectl cluster-info

B1 Systems GmbH Container Orchestration with Kubernetes 19 / 55

Page 20: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Kubernetes Worker

/etc/kubernetes/kubelet – on each worker nodeKUBELET_ADDRESS="--address=0.0.0.0"KUBELET_HOSTNAME="--hostname-override=node1"KUBELET_API_SERVER="--api-servers=http://node1:8080"KUBELET_ARGS=""

/etc/kubernetes/config – on each worker nodeKUBE_LOGTOSTDERR="--logtostderr=true"KUBE_LOG_LEVEL="--v=0"KUBE_ALLOW_PRIV="--allow-privileged=false"KUBE_MASTER="--master=http://node1:8080"

B1 Systems GmbH Container Orchestration with Kubernetes 20 / 55

Page 21: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Kubernetes Worker Start and Check1 Start master components on node2 , node3 ,node1 (optional):

# systemctl start kubelet kube-proxy

2 Check if both are running on node2, node3, node1 (optional):

# systemctl is-active "kube*"

3 Get cluster nodes’ states, execute on node1:

# kubectl get nodes

B1 Systems GmbH Container Orchestration with Kubernetes 21 / 55

Page 22: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Kubernetes cli – kubectl

B1 Systems GmbH Container Orchestration with Kubernetes 22 / 55

Page 23: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

kubectlconfiguration toolmanage and maintain kubernetes clusterstalks to api serverdefault config file in /.kube/config

comes with shell completion

# kubectl completion __SHELL__

e.g. bash completion

# source <(kubectl completion bash)

B1 Systems GmbH Container Orchestration with Kubernetes 23 / 55

Page 24: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

kubectl Examples 1

List and get detailed information about nodes in cluster:

# kubectl get nodes# kubectl describe nodes

Make node unschedulable (+ draining pods) and schedulable:

# kubectl cordon nodes# kubectl drain nodes# kubectl uncordon nodes

B1 Systems GmbH Container Orchestration with Kubernetes 24 / 55

Page 25: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

kubectl Examples 2

Manage entities and applications:

# kubectl get (pods|replicasets|service) (-o wide|yaml) (-w)# kubectl create -f __ENTITY.YAML__# kubectl delete (pod|replicaset|service) __ENTITYNAME__

Use for debugging of platform and applications:

# kubectl get events# kubectl describe node (__NODE1__)# kubectl logs (-f) __POD_NAME__

B1 Systems GmbH Container Orchestration with Kubernetes 25 / 55

Page 26: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Applications with Kubernetes

B1 Systems GmbH Container Orchestration with Kubernetes 26 / 55

Page 27: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Pods 1

smallest entityone IP addressconsists of min. 2 containers

1 infra container image (gcr.io/google_containers/pause-amd64:3.0, keepsnetwork namespace)min. 1 app container (e.g. nginx)

other entities can control pods by matching labelsstateless way of thinking:

1 delete2 restart↪→ work the same way as before (different parameters: ip address, hostname)

B1 Systems GmbH Container Orchestration with Kubernetes 27 / 55

Page 28: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Create a file pod.yamlapiVersion: v1kind: Podmetadata:

labels:run: nginx

name: mynginxnamespace: default

spec:containers:- name: nginxcont

image: nginx:latestimagePullPolicy: Alwaysenv:- name: LOGDIR

value: /srv/logs

B1 Systems GmbH Container Orchestration with Kubernetes 28 / 55

Page 29: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Working with Pods

Start the pod:

# kubectl create -f pod.yaml

Get information about pods:

# kubectl get pods# kubectl get pods -o wide# kubectl get pods mynginx -o yaml

B1 Systems GmbH Container Orchestration with Kubernetes 29 / 55

Page 30: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Replicasets/Replication Controller

controlling entitykeeps track of running (number of) podsfind pods to control by a matching labelrun = nginxstage = test

Replicaset same as ReplicationControllerReplicaset additonally supports matchLabels selector out of given quantities stagein (dev, test)

keyword replicas defines number of running pods

B1 Systems GmbH Container Orchestration with Kubernetes 30 / 55

Page 31: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Replicasets – Label Matchingreplicaset yaml...spec:

selector:matchLabels:

run: nginx...

pod yaml...metadata:

labels:run: nginx

...B1 Systems GmbH Container Orchestration with Kubernetes 31 / 55

Page 32: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Deploymentsspecial entity to control versioning of other entities (e.g. replicasets) and yourapplicationsbased on used images you can update, downgradessupports different update strategies:

rolling update – ”step by step” e.g.:1 stop one pod with old application version2 start one pod with new application version3 stop next pod with old application version4 start . . .

recreate update1 stop all pods with old application version2 start all pods with new application version

undo/redo operations supported

B1 Systems GmbH Container Orchestration with Kubernetes 32 / 55

Page 33: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

depl.yamlapiVersion: extensions/v1beta1kind: Deploymentmetadata:

name: nginx-deploymentspec:

replicas: 1strategy:

type: RollingUpdatetemplate:

spec:containers:- name: nginxpod

image: nginximagePullPolicy: Always

B1 Systems GmbH Container Orchestration with Kubernetes 33 / 55

Page 34: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Deployment InspectionCreate a deployment using the following command:

# kubectl create -f /home/tux/k8s/depl.yaml

Get information about pods:

# kubectl get deployment -o yaml# kubectl get replicaset# kubectl get pods

Name scheme:

|- Deployment: <name>| |-Replica Set: <name>-<integervalue>| |-Pod: <name>-<integervalue>-<randomString>

B1 Systems GmbH Container Orchestration with Kubernetes 34 / 55

Page 35: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Updates with Deployments

1 Change version of image in deployment yaml:

- image: nginx:1.12+ image: nginx:1.13

2 Apply new yaml to api:

# kubectl apply -f depl.yaml --record

B1 Systems GmbH Container Orchestration with Kubernetes 35 / 55

Page 36: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Undo and History

1 List revision history:

# kubectl rollout history deployment nginx-deployment

2 Hint: compare revision count with number of replicasets:

# kubectl get rs

3 Undo operation by jumping to specific revision:

# kubectl rollout undo deployment nginx-deployment --to-revision=1

B1 Systems GmbH Container Orchestration with Kubernetes 36 / 55

Page 37: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

External Access to Applications

B1 Systems GmbH Container Orchestration with Kubernetes 37 / 55

Page 38: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Services

entities representing one application to other applicationsalso the way to present your application to outside worlduses combination of virtual IP addresses + port + transport protocoldoes not change on upgrade or downgrade of your appshides internal addresses of applicationssupports loadbalancing to several pods of the same kind (same app)

B1 Systems GmbH Container Orchestration with Kubernetes 38 / 55

Page 39: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Service Handling

Create the service# kubectl create -f svc.yaml

Test and get information about service# curl -vvv http://localhost:32222# kubectl get svc -o yaml# kubectl get ep

B1 Systems GmbH Container Orchestration with Kubernetes 39 / 55

Page 40: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

External serviceapiVersion: v1kind: Servicemetadata:

name: nginx-svcnamespace: default

spec:selector:

run: nginxpodports:- name: nginx-port

port: 8080targetPort: 80protocol: TCPnodePort: 32222

type: NodePort

B1 Systems GmbH Container Orchestration with Kubernetes 40 / 55

Page 41: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

External serviceapiVersion: v1kind: Servicemetadata:

name: nginx-svcnamespace: default

spec:selector:

run: nginxpodports:- name: nginx-port

port: 8080targetPort: 80protocol: TCPnodePort: 33333

type: NodePortsessionAffinity: ClientIP

B1 Systems GmbH Container Orchestration with Kubernetes 41 / 55

Page 42: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Volumes, Configuration, Secrets

B1 Systems GmbH Container Orchestration with Kubernetes 42 / 55

Page 43: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Volumes

a way to save data outside the r/w-layerpersistent

shared filesystem needed to save cluster-wideexternal storage provider (cephfs, netapp) supportede.g. hostpath, host-based mount, on each k8s worker same host path must exist

temporaryvolume lifetime = pod lifetime on a nodethink of a typical Linux-like tmp directorye.g. emptydir

special volumes: configmap, secret

B1 Systems GmbH Container Orchestration with Kubernetes 43 / 55

Page 44: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Volume Example hostpath

hostpath volume in pod yamlspec:

containers:[...]

volumeMounts:- mountPath: /etc/nginx/conf.d

name: nginx-config-volumevolumes:- hostPath:

path: /mnt/configurationfilesname: nginx-config-volume

B1 Systems GmbH Container Orchestration with Kubernetes 44 / 55

Page 45: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Configmaps

get variable data into your podcluster-wide, independent from other entitiesdifferent way to create configuration datarepresenting data in different ways in pods

file-based (via volumes)environment variables (since v1.6)

B1 Systems GmbH Container Orchestration with Kubernetes 45 / 55

Page 46: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Create configmap# kubectl create configmap dbconfig --from-file=dbconfig.properties

Use configmap as volume in podspec:

containers:- name: nginxcont

[...]volumeMounts:

- name: config-volumemountPath: /etc/config

volumes:- name: config-volume

configMap:name: dbconfig

B1 Systems GmbH Container Orchestration with Kubernetes 46 / 55

Page 47: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Configmap with evironment variablesapiVersion: v1kind: ConfigMapmetadata:

name: dbconfig-envdata:

SERVER: db.example.orgUSERNAME: dbuserDATABASE: test

Usage in podContainers:[...]

envFrom:- configMapRef:

name: dbconfig-env

B1 Systems GmbH Container Orchestration with Kubernetes 47 / 55

Page 48: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Secrets

centralized way to save sensitive data as passwords, tokens, keysnot in cleartext, but base64more flexible way of saving secure information compared to a podsimilar to configmaps

key/value from files or standard inputdata presented as

file (file name = KEY, content = VALUE)ENV variable (name = userdef., content = value)

B1 Systems GmbH Container Orchestration with Kubernetes 48 / 55

Page 49: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Create secret from file# kubectl create secret generic secret1 --from-file=password

Use as volume in podspec:

containers:- name: nginxcont

[...]volumeMounts:

- name: secretvolmountPath: /etc/config/access

volumes:- name: secretvol

secret:secretName: secret1

B1 Systems GmbH Container Orchestration with Kubernetes 49 / 55

Page 50: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Secret Presented as Environment Variable in Pod

Use as volume in podcontainers:[...]

env:- name: PASSWORD

valueFrom:secretKeyRef:

name: secret1key: password

B1 Systems GmbH Container Orchestration with Kubernetes 50 / 55

Page 51: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Advanced Features of Kubernetes

B1 Systems GmbH Container Orchestration with Kubernetes 51 / 55

Page 52: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Daemonsets

special entityrun a pod on each Kubernetes worker nodeExamples:

logging services which need to read logs from each nodeK8s master/additional components (apiserver, scheduler, flannel)

B1 Systems GmbH Container Orchestration with Kubernetes 52 / 55

Page 53: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Example daemonset yaml file 1/2apiVersion: extensions/v1beta1kind: DaemonSetmetadata:

name: fluentd-daemonsetnamespace: kube-system

spec:template:

metadata:labels:

run: fluentdenv: tst

[...]

B1 Systems GmbH Container Orchestration with Kubernetes 53 / 55

Page 54: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Example daemonset yaml file 2/2[...]

name: fluentdspec:

restartPolicy: Alwayscontainers:- name: fluentd

image: gcr.io/google_containers/fluentd-elasticsearch:1.19env:- name: FLUENTD_ARGS

value: -qq

B1 Systems GmbH Container Orchestration with Kubernetes 54 / 55

Page 55: OpenSourceSummitEuropeOctober26,2017 · Container Orchestration with Kubernetes OpenSourceSummitEuropeOctober26,2017 Michael Steinfurth Linux/Unix Consultant & Trainer B1 …

Thank You!For more information, refer to [email protected]

or +49 (0)8457 - 931096