blob: deff35bc4c74c648920a20da5304908905da441d [file] [log] [blame]
marcoacdae7e2015-12-02 15:35:37 +01001
2==================
3Kubernetes Formula
4==================
5
Jakub Pavlik495d06f2016-06-17 11:33:05 +02006Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications.
7
8This formula deploys production ready Kubernetes and generate Kubernetes manifests as well.
marcoacdae7e2015-12-02 15:35:37 +01009
10Based on official Kubernetes salt
11https://github.com/kubernetes/kubernetes/tree/master/cluster/saltbase
12
13Extended on Contrail contribution https://github.com/Juniper/kubernetes/blob/opencontrail-integration/docs/getting-started-guides/opencontrail.md
14
15
16Sample pillars
17==============
18
Ales Komarek688a04c2016-07-15 15:12:30 +020019Containers on pool definitions in pool.service.local
20
Jakub Pavlik7e985322016-07-17 13:16:15 +020021.. code-block:: yaml
22
23 parameters:
24 kubernetes:
25 pool:
26 service:
27 local:
28 enabled: False
29 service: libvirt
30 cluster: openstack-compute
31 namespace: default
32 role: ${linux:system:name}
33 type: LoadBalancer
34 kind: Deployment
35 apiVersion: extensions/v1beta1
36 replicas: 1
37 host_pid: True
38 nodeSelector:
39 - key: openstack
40 value: ${linux:system:name}
41 hostNetwork: True
42 container:
43 libvirt-compute:
44 privileged: True
45 image: ${_param:docker_repository}/libvirt-compute
46 tag: ${_param:openstack_container_tag}
Ales Komarek688a04c2016-07-15 15:12:30 +020047
48Master definition
49
marcoacdae7e2015-12-02 15:35:37 +010050.. code-block:: yaml
51
52 kubernetes:
Jakub Pavlik495d06f2016-06-17 11:33:05 +020053 master:
54 addons:
55 dns:
56 domain: cluster.local
57 enabled: true
58 replicas: 1
59 server: 10.254.0.10
Jakub Pavlik495d06f2016-06-17 11:33:05 +020060 admin:
61 password: password
62 username: admin
63 apiserver:
64 address: 10.0.175.100
65 port: 8080
66 ca: kubernetes
67 enabled: true
68 etcd:
69 host: 127.0.0.1
70 members:
71 - host: 10.0.175.100
72 name: node040
73 name: node040
74 token: ca939ec9c2a17b0786f6d411fe019e9b
75 kubelet:
76 allow_privileged: true
77 network:
78 engine: calico
79 hash: fb5e30ebe6154911a66ec3fb5f1195b2
80 private_ip_range: 10.150.0.0/16
81 version: v0.19.0
82 service_addresses: 10.254.0.0/16
83 storage:
84 engine: glusterfs
85 members:
86 - host: 10.0.175.101
87 port: 24007
88 - host: 10.0.175.102
89 port: 24007
90 - host: 10.0.175.103
91 port: 24007
92 port: 24007
93 token:
94 admin: DFvQ8GJ9JD4fKNfuyEddw3rjnFTkUKsv
95 controller_manager: EreGh6AnWf8DxH8cYavB2zS029PUi7vx
96 dns: RAFeVSE4UvsCz4gk3KYReuOI5jsZ1Xt3
97 kube_proxy: DFvQ8GelB7afH3wClC9romaMPhquyyEe
98 kubelet: 7bN5hJ9JD4fKjnFTkUKsvVNfuyEddw3r
99 logging: MJkXKdbgqRmTHSa2ykTaOaMykgO6KcEf
100 monitoring: hnsj0XqABgrSww7Nqo7UVTSZLJUt2XRd
101 scheduler: HY1UUxEPpmjW4a1dDLGIANYQp1nZkLDk
102 version: v1.2.4
103
marcoacdae7e2015-12-02 15:35:37 +0100104
105 kubernetes:
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200106 pool:
107 address: 0.0.0.0
108 allow_privileged: true
109 ca: kubernetes
110 cluster_dns: 10.254.0.10
111 cluster_domain: cluster.local
112 enabled: true
113 kubelet:
114 allow_privileged: true
115 config: /etc/kubernetes/manifests
116 frequency: 5s
117 master:
118 apiserver:
119 members:
120 - host: 10.0.175.100
121 etcd:
122 members:
123 - host: 10.0.175.100
124 host: 10.0.175.100
125 network:
126 engine: calico
127 hash: fb5e30ebe6154911a66ec3fb5f1195b2
128 version: v0.19.0
129 token:
130 kube_proxy: DFvQ8GelB7afH3wClC9romaMPhquyyEe
131 kubelet: 7bN5hJ9JD4fKjnFTkUKsvVNfuyEddw3r
132 version: v1.2.4
marcoacdae7e2015-12-02 15:35:37 +0100133
134
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200135
136Kubernetes with OpenContrail network plugin
137------------------------------------------------
marcoacdae7e2015-12-02 15:35:37 +0100138
139On Master:
140
141.. code-block:: yaml
142
143 kubernetes:
144 master:
145 network:
146 engine: opencontrail
147 host: 10.0.170.70
148 port: 8082
149 default_domain: default-domain
150 default_project: default-domain:default-project
151 public_network: default-domain:default-project:Public
152 public_ip_range: 185.22.97.128/26
153 private_ip_range: 10.150.0.0/16
154 service_cluster_ip_range: 10.254.0.0/16
155 network_label: name
156 service_label: uses
157 cluster_service: kube-system/default
158 network_manager:
159 image: pupapaik/opencontrail-kube-network-manager
160 tag: release-1.1-jpa-final-1
161
162On pools:
163
164.. code-block:: yaml
165
166 kubernetes:
167 pool:
168 network:
169 engine: opencontrail
170
Jakub Pavlik1cfc1fe2016-07-25 11:01:52 +0200171Kubernetes control plane running in systemd
172-------------------------------------------
173
174By default kube-apiserver, kube-scheduler, kube-controllermanager, kube-proxy, etcd running in docker containers through manifests. For stable production environment this should be run in systemd.
175
176.. code-block:: yaml
177
178 kubernetes:
179 master:
180 container: false
181
182 kubernetes:
183 pool:
184 container: false
185
marco055ff852016-07-27 15:22:33 +0200186Because k8s services run under kube user without root privileges, there is need to change secure port for apiserver.
187
188.. code-block:: yaml
189
190 kubernetes:
191 master:
192 apiserver:
193 secure_port: 8081
194
marcoacdae7e2015-12-02 15:35:37 +0100195Kubernetes with Flannel
196-----------------------
197
198On Master:
199
200.. code-block:: yaml
201
202 kubernetes:
203 master:
204 network:
205 engine: flannel
Jakub Pavlik7e985322016-07-17 13:16:15 +0200206 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200207 etcd:
208 members:
209 - host: 10.0.175.101
210 port: 4001
211 - host: 10.0.175.102
212 port: 4001
213 - host: 10.0.175.103
214 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100215 common:
216 network:
217 engine: flannel
218
219On pools:
220
221.. code-block:: yaml
222
223 kubernetes:
224 pool:
225 network:
226 engine: flannel
marcoa05621f2016-07-14 10:35:24 +0200227 etcd:
228 members:
229 - host: 10.0.175.101
230 port: 4001
231 - host: 10.0.175.102
232 port: 4001
233 - host: 10.0.175.103
234 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100235 common:
236 network:
237 engine: flannel
238
239Kubernetes with Calico
240-----------------------
241
242On Master:
243
244.. code-block:: yaml
245
246 kubernetes:
247 master:
248 network:
249 engine: calico
Jakub Pavlik7e985322016-07-17 13:16:15 +0200250 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200251 etcd:
252 members:
253 - host: 10.0.175.101
254 port: 4001
255 - host: 10.0.175.102
256 port: 4001
257 - host: 10.0.175.103
258 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100259
260On pools:
261
262.. code-block:: yaml
263
264 kubernetes:
265 pool:
266 network:
267 engine: calico
marcoa05621f2016-07-14 10:35:24 +0200268 etcd:
269 members:
270 - host: 10.0.175.101
271 port: 4001
272 - host: 10.0.175.102
273 port: 4001
274 - host: 10.0.175.103
275 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100276
Jakub Pavlik7e985322016-07-17 13:16:15 +0200277Post deployment configuration
278
279.. code-block:: bash
Jakub Pavlik232833c2016-07-17 13:21:00 +0200280
Jakub Pavlik7e985322016-07-17 13:16:15 +0200281 # set ETCD
282 export ETCD_AUTHORITY=10.0.111.201:4001
283
284 # Set NAT for pods subnet
285 calicoctl pool add 192.168.0.0/16 --nat-outgoing
286
287 # Status commands
288 calicoctl status
289 calicoctl node show
290
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200291Kubernetes with GlusterFS for storage
292---------------------------------------------
293
294.. code-block:: yaml
295
296 kubernetes:
297 master
298 ...
299 storage:
300 engine: glusterfs
301 port: 24007
302 members:
303 - host: 10.0.175.101
304 port: 24007
305 - host: 10.0.175.102
306 port: 24007
307 - host: 10.0.175.103
308 port: 24007
309 ...
310
marco45fc1b72016-07-02 16:11:18 +0200311Kubernetes namespaces
312---------------------
313
314Create namespace:
315
316.. code-block:: yaml
317
318 kubernetes:
319 master
320 ...
321 namespace:
322 kube-system:
323 enabled: True
324 namespace2:
325 enabled: True
326 namespace3:
327 enabled: False
328 ...
329
330Kubernetes labels
331-----------------
332
333Create namespace:
334
335.. code-block:: yaml
336
337 kubernetes:
338 pool
339 ...
340 host:
341 label:
342 key01:
343 value: value01
344 enable: True
345 key02:
346 value: value02
347 enable: False
348 name: ${linux:system:name}
349 ...
350
marcof7efecb2016-07-16 16:13:37 +0200351Pull images from private registries
352-----------------------------------
353
354.. code-block:: yaml
355
356 kubernetes:
357 master
358 ...
359 registry:
360 secret:
361 registry01:
362 enabled: True
363 key: (get from `cat /root/.docker/config.json | base64`)
364 namespace: default
365 ...
366 control:
367 ...
368 service:
369 service01:
370 ...
371 image_pull_secretes: registry01
372 ...
373
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200374Kubernetes Service Definitions in pillars
375==========================================
376
377Following samples show how to generate kubernetes manifest as well and provide single tool for complete infrastructure management.
378
379Deployment manifest
380---------------------
marcoacdae7e2015-12-02 15:35:37 +0100381
382.. code-block:: yaml
383
384 salt:
385 control:
386 enabled: True
387 hostNetwork: True
388 service:
389 memcached:
390 privileged: True
391 service: memcached
392 role: server
393 type: LoadBalancer
394 replicas: 3
395 kind: Deployment
396 apiVersion: extensions/v1beta1
397 ports:
398 - port: 8774
399 name: nova-api
400 - port: 8775
401 name: nova-metadata
402 volume:
403 volume_name:
404 type: hostPath
405 mount: /certs
406 path: /etc/certs
407 container:
408 memcached:
409 image: memcached
410 tag:2
411 ports:
412 - port: 8774
413 name: nova-api
414 - port: 8775
415 name: nova-metadata
416 variables:
417 - name: HTTP_TLS_CERTIFICATE:
418 value: /certs/domain.crt
419 - name: HTTP_TLS_KEY
420 value: /certs/domain.key
421 volumes:
422 - name: /etc/certs
423 type: hostPath
424 mount: /certs
425 path: /etc/certs
426
marcobe30c8d2016-10-11 19:16:35 +0200427PetSet manifest
428---------------------
429
430.. code-block:: yaml
431
432 service:
433 memcached:
434 apiVersion: apps/v1alpha1
435 kind: PetSet
436 service_name: 'memcached'
437 container:
438 memcached:
439 ...
440
441
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200442Configmap
443---------
444
445You are able to create configmaps using support layer between formulas.
446It works simple, eg. in nova formula there's file ``meta/config.yml`` which
447defines config files used by that service and roles.
448
449Kubernetes formula is able to generate these files using custom pillar and
450grains structure. This way you are able to run docker images built by any way
451while still re-using your configuration management.
452
453Example pillar:
454
455.. code-block:: bash
456
457 kubernetes:
458 control:
Jakub Pavlika2779722016-11-25 15:35:26 +0100459 config_type: default|kubernetes # Output is yaml k8s or default single files
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200460 configmap:
461 nova-control:
462 grains:
463 # Alternate grains as OS running in container may differ from
464 # salt minion OS. Needed only if grains matters for config
465 # generation.
466 os_family: Debian
467 pillar:
468 # Generic pillar for nova controller
469 nova:
470 controller:
471 enabled: true
472 versionn: liberty
473 ...
474
475To tell which services supports config generation, you need to ensure pillar
476structure like this to determine support:
477
478.. code-block:: yaml
479
480 nova:
481 _support:
482 config:
483 enabled: true
484
marcod4d3dbd2016-09-27 11:36:40 +0200485initContainers
486--------------
487
488Example pillar:
489
490.. code-block:: bash
491
492 kubernetes:
493 control:
494 service:
495 memcached:
496 init_containers:
497 - name: test-mysql
498 image: busybox
499 command:
500 - sleep
501 - 3600
502 volumes:
503 - name: config
504 mount: /test
505 - name: test-memcached
506 image: busybox
507 command:
508 - sleep
509 - 3600
510 volumes:
511 - name: config
512 mount: /test
513
marcoee859d32016-11-07 11:04:57 +0100514Affinity
515--------
516
517podAffinity
518===========
519
520Example pillar:
521
522.. code-block:: bash
523
524 kubernetes:
525 control:
526 service:
527 memcached:
528 affinity:
529 pod_affinity:
530 name: podAffinity
531 expression:
532 label_selector:
533 name: labelSelector
534 selectors:
535 - key: app
536 value: memcached
537 topology_key: kubernetes.io/hostname
538
539podAntiAffinity
540===============
541
542Example pillar:
543
544.. code-block:: bash
545
546 kubernetes:
547 control:
548 service:
549 memcached:
550 affinity:
551 anti_affinity:
552 name: podAntiAffinity
553 expression:
554 label_selector:
555 name: labelSelector
556 selectors:
557 - key: app
558 value: opencontrail-control
559 topology_key: kubernetes.io/hostname
560
561nodeAffinity
562===============
563
564Example pillar:
565
566.. code-block:: bash
567
568 kubernetes:
569 control:
570 service:
571 memcached:
572 affinity:
573 node_affinity:
574 name: nodeAffinity
575 expression:
576 match_expressions:
577 name: matchExpressions
578 selectors:
579 - key: key
580 operator: In
581 values:
582 - value1
583 - value2
584
marcoacdae7e2015-12-02 15:35:37 +0100585Volumes
586-------
587
588hostPath
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200589==========
marcoacdae7e2015-12-02 15:35:37 +0100590
591.. code-block:: yaml
592
marcob469f882016-09-27 09:56:13 +0200593 service:
marcoacdae7e2015-12-02 15:35:37 +0100594 memcached:
marcob469f882016-09-27 09:56:13 +0200595 container:
596 memcached:
597 volumes:
598 - name: volume1
599 mountPath: /volume
600 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100601 ...
marcob469f882016-09-27 09:56:13 +0200602 volume:
603 volume1:
604 name: /etc/certs
605 type: hostPath
606 path: /etc/certs
marcoacdae7e2015-12-02 15:35:37 +0100607
608emptyDir
Ales Komarek688a04c2016-07-15 15:12:30 +0200609========
marcoacdae7e2015-12-02 15:35:37 +0100610
611.. code-block:: yaml
612
marcob469f882016-09-27 09:56:13 +0200613 service:
marcoacdae7e2015-12-02 15:35:37 +0100614 memcached:
marcob469f882016-09-27 09:56:13 +0200615 container:
616 memcached:
617 volumes:
618 - name: volume1
619 mountPath: /volume
620 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100621 ...
marcob469f882016-09-27 09:56:13 +0200622 volume:
623 volume1:
624 name: /etc/certs
625 type: emptyDir
626
627configMap
628=========
629
630.. code-block:: yaml
631
632 service:
633 memcached:
634 container:
635 memcached:
636 volumes:
637 - name: volume1
638 mountPath: /volume
639 readOnly: True
640 ...
641 volume:
642 volume1:
643 type: config_map
644 item:
645 configMap1:
646 key: config.conf
647 path: config.conf
648 configMap2:
649 key: policy.json
650 path: policy.json
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200651
marco0eda4fb2016-10-10 19:08:27 +0200652To mount single configuration file instead of whole directory:
653
654.. code-block:: yaml
655
656 service:
657 memcached:
658 container:
659 memcached:
660 volumes:
661 - name: volume1
662 mountPath: /volume/config.conf
663 sub_path: config.conf
664
marcofcc20d02016-10-10 09:56:12 +0200665Generating Jobs
666===============
667
668Example pillar:
669
670.. code-block:: yaml
671
672 kubernetes:
673 control:
674 job:
675 sleep:
676 job: sleep
677 restart_policy: Never
678 container:
679 sleep:
680 image: busybox
681 tag: latest
682 command:
683 - sleep
684 - "3600"
685
686Volumes and Variables can be used as the same way as during Deployment generation.
687
688Custom params:
689
690.. code-block:: yaml
691
692 kubernetes:
693 control:
694 job:
695 host_network: True
696 host_pid: True
697 container:
698 sleep:
699 privileged: True
700 node_selector:
701 key: node
702 value: one
703 image_pull_secretes: password
704
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200705Documentation and Bugs
Filip Pytloun06a55402016-08-12 14:53:30 +0200706======================
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200707
708To learn how to deploy OpenStack Salt, consult the documentation available
709online at:
710
711 https://wiki.openstack.org/wiki/OpenStackSalt
712
713In the unfortunate event that bugs are discovered, they should be reported to
714the appropriate bug tracker. If you obtained the software from a 3rd party
715operating system vendor, it is often wise to use their own bug tracker for
716reporting problems. In all other cases use the master OpenStack bug tracker,
717available at:
718
719 http://bugs.launchpad.net/openstack-salt
720
721Developers wishing to work on the OpenStack Salt project should always base
722their work on the latest formulas code, available from the master GIT
723repository at:
724
725 https://git.openstack.org/cgit/openstack/salt-formula-kubernetes
726
727Developers should also join the discussion on the IRC list, at:
728
729 https://wiki.openstack.org/wiki/Meetings/openstack-salt
Filip Pytloun06a55402016-08-12 14:53:30 +0200730
731Copyright and authors
732=====================
733
734(c) 2016 tcp cloud a.s.
735(c) 2016 OpenStack Foundation