-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubernetes-getting-started.slide
373 lines (217 loc) · 7.55 KB
/
kubernetes-getting-started.slide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
Kubernetes Getting Started
Apr 2018
Ilias Dimos
DevOps Engineer, Pollfish
@dosko64
* Docker Athens Meetup
.image images/docker.png
* About
* What is Kubernetes?
- Open source
: Google open-sourced the Kubernetes project in 2014
- Highly available
: Through scheduling and healthchecking
- Managing containers
- Backed by a big community
- A lot of enteprises put effort on the project
.image images/kubernetes.png
* Why Kubernetes
- Run new code in production without setting up servers
- Fail over capabilities
- Easy see what you are running in the cluster
- Better use of your resources
* Setup
- Local
- Minikube
- Tools to setup your cluster
- kubeadm
- kops
- kubicorn
- Cli tool
- kubectl
* Providers
- Cloud
- Google Kubernetes Engine
- Microsoft ACS Engine and AKS Engine
- Amazon EKS
Enterprise Solutions
- Juju by Canonical
- Tectonic by CoreOS
- Docker Enterprise
- More at:
.link https://kubernetes.io/docs/setup/pick-right-solution/
There are a lot of resources out there on how to setup you cluster
* Architecture
Node Types:
- Master
: Master - Node Controllers - a component which manages various aspects of nodes
: health, scheduling
: availability, internal list of nodes up to date
- Worker
: worker - reponsible for running our apps, our payloads
kubectl get nodes
* Architecture
- kubelet
: - kubelet - The agent that runs on each node
- kube-apiserver
: - kube-apiserver - REST operations with the cluster
- kube-controller-manager
: kube controller-manager - the core control loops shipped with Kubernetes
: -- Watches the shared state of the cluster, throught the apiserver, and makes changes towards the desired state,
: --- includes replication namespace serviceaccount controllers etc.
- kube-scheduler
: kube-scheduler - Watches over the cluster and acts accordingly to ensuer kube-controller-managere's requests. All are exposed through the API as necessary.
- etcd
: etcd -- key value store used to store the state of the cluster
* Components:
- *Pod*
: pod - The smallest deployable object, can contain 1 or more docker containers.
- *ReplicationController* - Deprecated -
: Replication Controller - enables you to easily create multiple pods, then make sure that that number of pods always exists
- *ReplicaSet*
: ReplicaSet - Enables easily create multiple pods. Ensures a given nuber of pods always run. Keep history of deployments. Advance selector.
- *Deployment*
: Deployment - Replacement of RC, replication through RS, Rollout/rollback abilities.
kubectl get pods
kubectl get rs
kubectl get deployment
kubectl get rc
kubectl get all
* Okay, how i connect to this ?
Services
: Service - The entity that give us (loadbalanced) access to selected deployments/pods determined by labels
: Service are of the following types:
- ClusterIP
- NodePort
- LoadBalancer
Ingress
: Ingress - a collection of rules that allow inbound connections to reach the cluster services.
: Imagine an Nginx in your cluster, with SSL termination and name-based routing
.code examples/ingress.yaml
kubectl get svc
kubectl get ingress
* Namespace
- Virtual clusters in the same physical cluster
kubectl get namespace
kubectl get all --all-namespaces
- Kubeconfig
Env Variables
KUBECONFIG
Default ~/.kube/config
kubectl config view
kubectl config set-context prod --cluster='kluster' --namespace='production' --user='kubelet'
kubectl config use-context prod
kubeconfig is a yaml file, so you can edit it by hand
* Recap Components
.image images/Kube_basic_example.jpg
* Tools
- kubectl
: imperative
** Demo
Basic kubectl commands
kubectl run nginx --image=nginx --port=80
kubectl expose deployment nginx --target-port=80 --type=NodePort
kubectl get pods | deployment | svc | all
kubectl describe <resource>
kubectl logs <pod_name>
kubectl exec <pod_name> cmd
kubectl exec -it <pod_name> bash
kubectl proxy
: kubectl proxy, at http://localhost:8001/apis/ you can see the apis available in your cluster
* Working stack
- Use Yaml files (on git) for definitions for :
Deployment (which includes -> ReplicaSet -> Pods)
Service
* Deployment Simple Example
.code -edit examples/deployment_simple.yaml
* Deployment Full Example
.code -edit examples/deployment1.yaml
--> to be continued to editor deployment.yaml
* Service Example
.code -edit examples/service.yaml
* Components part. 2
- Volumes
: volumes: A way to persist data to some kind of disk
: based on the driver
: it's everything we expect from docker volumes to be, with a broader spectrum
- Configmaps
: Configmaps - Save your configurations to etcd and use them as a volume to pods
- Secrets
: ---------
: Secrets
: Secrets contains a small amount of sensitive data such as a password
: use them as volumes in pods
- Daemonset
: ---------
: Daemonset
: - A DaemonSet ensures that all (or some) Nodes run a copy of a Pod.
- StatefulSets
: ---------
: StatefulSets
: -- provide guarantees about the ordering and uniqueness of these Pods.
: -- are valuable for applications that require one or more of the following.
: -- Stable, unique network identifiers.
: -- Stable, persistent storage.
: -- Ordered, graceful deployment and scaling.
: -- Ordered, graceful deletion and termination.
: -- Ordered, automated rolling updates.
- Jobs
: ---------
: Jobs
: --- A job creates one or more pods and ensures that a specified number of them successfully terminate.
- Cronjobs
: ---------
: Jobs
: ---- A Cron Job manages time based Jobs, namely:
: ---- Once at a specified point in time
: ---- Repeatedly at a specified point in time
* Configmaps
.code examples/config.yaml
* Configmaps as Volume
.code examples/volume_config.yaml
* Demo (2)
Deployment and service
: Create replace deployment
kubectl create -f examples/deployment_simple.yaml
kubectl create -f examples/service.yaml
kubectl replace -f examples/deployment_simple.yaml
kubectl set image deployment/worker worker=goweb:0.2
: Scale
kubectl scale --replicas=3 -f examples/deployment_simple.yaml
kubectl scale --replicas=1 deployment/worker
: Rollback deployment
kubectl rollout status deployment app-deployment
kubectl rollout history deployment app-deployment
kubectl rollout undo worker
* Final Notes
- We need Service and Deployment definition for all your workloads
- Create your services wisely and before deployments
- KubeDNS provide access to services in the form of:
<service-name>.<namespace>.svc
- For everyting up to creation time, in pods, all resources are available in environmental variables
- Environmental Variables for configuration in your apps (12 factor app)
- Create healthcheck in your apps
- Always apply limits for pods
- Version your docker images and don't use latest
* Usefull shortcuts
alias k='kubectl'
alias kg='kubectl get'
alias kga='kubectl get all'
alias kgan='kubectl get all --all-namespaces'
alias kcc='kubectl config use-context'
alias kl='kubectl logs'
alias klf='kubectl logs -f'
alias kd='kubectl describe'
alias ksn='kubectl -n kube-system'
Tools Suggestions:
- oh-my-zsh kubectl autocomplete
- VSCode kubernetes plugin
* Next steps
- RBAC
- Helm
- CI/CD consepts
* Presentation Available at
.link https://go-talks.appspot.com/github.com/dosko64/kubernetes-getting-started/kubernetes-getting-started.slide
and code at
.link https://github.com/dosko64/kubernetes-getting-started