blob: 98785ed2906dc9fdd48ac316c67c7b169669ea86 [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
Tomáš Kukrál189da4b2017-01-18 14:30:09 +010019**REQUIRED:** Define image to use for hyperkube, CNIs and calicoctl image
20
21.. code-block:: yaml
22
23 parameters:
24 kubernetes:
25 common:
26 hyperkube:
Tomáš Kukrála636f0e2017-03-21 11:09:55 +010027 image: gcr.io/google_containers/hyperkube:v1.5.2
Tomáš Kukrál189da4b2017-01-18 14:30:09 +010028 pool:
29 network:
30 calicoctl:
31 image: calico/ctl
32 cni:
33 image: calico/cni
34
Tomáš Kukrál25a64d72017-03-23 14:14:07 +010035Enable helm-tiller addon
Tomáš Kukrál1b50f772017-03-23 12:51:32 +010036
37.. code-block:: yaml
38
39 parameters:
40 kubernetes:
41 master:
42 addons:
43 helm:
44 enabled: true
45
Tomáš Kukrál25a64d72017-03-23 14:14:07 +010046Enable netchecker addon
47
48.. code-block:: yaml
49
50 parameters:
51 kubernetes:
52 master:
53 namespace:
54 netchecker:
55 enabled: true
56 addons:
57 netchecker:
58 enabled: true
Tomáš Kukrál1b50f772017-03-23 12:51:32 +010059
Tomáš Kukrál6ef3f892017-02-15 12:02:22 +010060Pass aditional parameters to daemons:
61
62.. code-block:: yaml
63
64 parameters:
65 kubernetes:
66 master:
67 apiserver:
68 daemon_opts:
69 storage-backend: pigeon
70 controller_manager:
71 daemon_opts:
72 log-dir: /dev/nulL
73 pool:
74 kubelet:
75 daemon_opts:
76 max-pods: "6"
77
Tomáš Kukrál189da4b2017-01-18 14:30:09 +010078
Ales Komarek688a04c2016-07-15 15:12:30 +020079Containers on pool definitions in pool.service.local
80
Jakub Pavlik7e985322016-07-17 13:16:15 +020081.. code-block:: yaml
82
83 parameters:
84 kubernetes:
85 pool:
86 service:
87 local:
88 enabled: False
89 service: libvirt
90 cluster: openstack-compute
91 namespace: default
92 role: ${linux:system:name}
93 type: LoadBalancer
94 kind: Deployment
95 apiVersion: extensions/v1beta1
96 replicas: 1
97 host_pid: True
98 nodeSelector:
99 - key: openstack
100 value: ${linux:system:name}
101 hostNetwork: True
102 container:
103 libvirt-compute:
104 privileged: True
105 image: ${_param:docker_repository}/libvirt-compute
106 tag: ${_param:openstack_container_tag}
Ales Komarek688a04c2016-07-15 15:12:30 +0200107
108Master definition
109
marcoacdae7e2015-12-02 15:35:37 +0100110.. code-block:: yaml
111
112 kubernetes:
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200113 master:
114 addons:
115 dns:
116 domain: cluster.local
117 enabled: true
118 replicas: 1
119 server: 10.254.0.10
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200120 admin:
121 password: password
122 username: admin
123 apiserver:
124 address: 10.0.175.100
Swann Croisetff97efc2017-02-23 13:32:33 +0100125 secure_port: 443
126 insecure_address: 127.0.0.1
127 insecure_port: 8080
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200128 ca: kubernetes
129 enabled: true
130 etcd:
131 host: 127.0.0.1
132 members:
133 - host: 10.0.175.100
134 name: node040
135 name: node040
136 token: ca939ec9c2a17b0786f6d411fe019e9b
137 kubelet:
138 allow_privileged: true
139 network:
140 engine: calico
141 hash: fb5e30ebe6154911a66ec3fb5f1195b2
142 private_ip_range: 10.150.0.0/16
143 version: v0.19.0
144 service_addresses: 10.254.0.0/16
145 storage:
146 engine: glusterfs
147 members:
148 - host: 10.0.175.101
149 port: 24007
150 - host: 10.0.175.102
151 port: 24007
152 - host: 10.0.175.103
153 port: 24007
154 port: 24007
155 token:
156 admin: DFvQ8GJ9JD4fKNfuyEddw3rjnFTkUKsv
157 controller_manager: EreGh6AnWf8DxH8cYavB2zS029PUi7vx
158 dns: RAFeVSE4UvsCz4gk3KYReuOI5jsZ1Xt3
159 kube_proxy: DFvQ8GelB7afH3wClC9romaMPhquyyEe
160 kubelet: 7bN5hJ9JD4fKjnFTkUKsvVNfuyEddw3r
161 logging: MJkXKdbgqRmTHSa2ykTaOaMykgO6KcEf
162 monitoring: hnsj0XqABgrSww7Nqo7UVTSZLJUt2XRd
163 scheduler: HY1UUxEPpmjW4a1dDLGIANYQp1nZkLDk
164 version: v1.2.4
165
marcoacdae7e2015-12-02 15:35:37 +0100166
167 kubernetes:
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200168 pool:
169 address: 0.0.0.0
170 allow_privileged: true
171 ca: kubernetes
172 cluster_dns: 10.254.0.10
173 cluster_domain: cluster.local
174 enabled: true
175 kubelet:
176 allow_privileged: true
177 config: /etc/kubernetes/manifests
178 frequency: 5s
179 master:
180 apiserver:
181 members:
182 - host: 10.0.175.100
183 etcd:
184 members:
185 - host: 10.0.175.100
186 host: 10.0.175.100
187 network:
188 engine: calico
189 hash: fb5e30ebe6154911a66ec3fb5f1195b2
190 version: v0.19.0
191 token:
192 kube_proxy: DFvQ8GelB7afH3wClC9romaMPhquyyEe
193 kubelet: 7bN5hJ9JD4fKjnFTkUKsvVNfuyEddw3r
194 version: v1.2.4
marcoacdae7e2015-12-02 15:35:37 +0100195
196
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200197
198Kubernetes with OpenContrail network plugin
199------------------------------------------------
marcoacdae7e2015-12-02 15:35:37 +0100200
201On Master:
202
203.. code-block:: yaml
204
205 kubernetes:
206 master:
207 network:
208 engine: opencontrail
209 host: 10.0.170.70
210 port: 8082
211 default_domain: default-domain
212 default_project: default-domain:default-project
213 public_network: default-domain:default-project:Public
214 public_ip_range: 185.22.97.128/26
215 private_ip_range: 10.150.0.0/16
216 service_cluster_ip_range: 10.254.0.0/16
217 network_label: name
218 service_label: uses
219 cluster_service: kube-system/default
220 network_manager:
221 image: pupapaik/opencontrail-kube-network-manager
222 tag: release-1.1-jpa-final-1
223
224On pools:
225
226.. code-block:: yaml
227
228 kubernetes:
229 pool:
230 network:
231 engine: opencontrail
232
Jakub Pavlik1cfc1fe2016-07-25 11:01:52 +0200233Kubernetes control plane running in systemd
234-------------------------------------------
235
236By 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.
237
238.. code-block:: yaml
239
240 kubernetes:
241 master:
242 container: false
243
244 kubernetes:
245 pool:
246 container: false
247
marco055ff852016-07-27 15:22:33 +0200248Because k8s services run under kube user without root privileges, there is need to change secure port for apiserver.
249
250.. code-block:: yaml
251
252 kubernetes:
253 master:
254 apiserver:
255 secure_port: 8081
256
marcoacdae7e2015-12-02 15:35:37 +0100257Kubernetes with Flannel
258-----------------------
259
260On Master:
261
262.. code-block:: yaml
263
264 kubernetes:
265 master:
266 network:
267 engine: flannel
Jakub Pavlik7e985322016-07-17 13:16:15 +0200268 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200269 etcd:
270 members:
271 - host: 10.0.175.101
272 port: 4001
273 - host: 10.0.175.102
274 port: 4001
275 - host: 10.0.175.103
276 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100277 common:
278 network:
279 engine: flannel
280
281On pools:
282
283.. code-block:: yaml
284
285 kubernetes:
286 pool:
287 network:
288 engine: flannel
marcoa05621f2016-07-14 10:35:24 +0200289 etcd:
290 members:
291 - host: 10.0.175.101
292 port: 4001
293 - host: 10.0.175.102
294 port: 4001
295 - host: 10.0.175.103
296 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100297 common:
298 network:
299 engine: flannel
300
301Kubernetes with Calico
302-----------------------
303
304On Master:
305
306.. code-block:: yaml
307
308 kubernetes:
309 master:
310 network:
311 engine: calico
Jakub Pavlik7e985322016-07-17 13:16:15 +0200312 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200313 etcd:
314 members:
315 - host: 10.0.175.101
316 port: 4001
317 - host: 10.0.175.102
318 port: 4001
319 - host: 10.0.175.103
320 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100321
322On pools:
323
324.. code-block:: yaml
325
326 kubernetes:
327 pool:
328 network:
329 engine: calico
marcoa05621f2016-07-14 10:35:24 +0200330 etcd:
331 members:
332 - host: 10.0.175.101
333 port: 4001
334 - host: 10.0.175.102
335 port: 4001
336 - host: 10.0.175.103
337 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100338
Tomáš Kukrál34c59362017-03-01 14:00:37 +0100339Running with secured etcd:
340
341.. code-block:: yaml
342
343 kubernetes:
344 pool:
345 network:
346 engine: calico
347 etcd:
348 ssl:
349 enabled: true
350 master:
351 network:
352 engine: calico
353 etcd:
354 ssl:
355 enabled: true
356
Jakub Pavlik7e985322016-07-17 13:16:15 +0200357Post deployment configuration
358
359.. code-block:: bash
Jakub Pavlik232833c2016-07-17 13:21:00 +0200360
Jakub Pavlik7e985322016-07-17 13:16:15 +0200361 # set ETCD
362 export ETCD_AUTHORITY=10.0.111.201:4001
363
364 # Set NAT for pods subnet
365 calicoctl pool add 192.168.0.0/16 --nat-outgoing
366
367 # Status commands
368 calicoctl status
369 calicoctl node show
370
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200371Kubernetes with GlusterFS for storage
372---------------------------------------------
373
374.. code-block:: yaml
375
376 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100377 master:
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200378 ...
379 storage:
380 engine: glusterfs
381 port: 24007
382 members:
383 - host: 10.0.175.101
384 port: 24007
385 - host: 10.0.175.102
386 port: 24007
387 - host: 10.0.175.103
388 port: 24007
389 ...
390
marco45fc1b72016-07-02 16:11:18 +0200391Kubernetes namespaces
392---------------------
393
394Create namespace:
395
396.. code-block:: yaml
397
398 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100399 master:
marco45fc1b72016-07-02 16:11:18 +0200400 ...
401 namespace:
402 kube-system:
403 enabled: True
404 namespace2:
405 enabled: True
406 namespace3:
407 enabled: False
408 ...
409
410Kubernetes labels
411-----------------
412
Marek Celoud901020b2017-01-27 14:51:41 +0100413Label node:
marco45fc1b72016-07-02 16:11:18 +0200414
415.. code-block:: yaml
416
Marek Celoud901020b2017-01-27 14:51:41 +0100417 kubernetes:
418 master:
419 label:
420 label01:
421 value: value01
422 node: node01
423 enabled: true
424 key: key01
marco45fc1b72016-07-02 16:11:18 +0200425 ...
marco45fc1b72016-07-02 16:11:18 +0200426
marcof7efecb2016-07-16 16:13:37 +0200427Pull images from private registries
428-----------------------------------
429
430.. code-block:: yaml
431
432 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100433 master:
marcof7efecb2016-07-16 16:13:37 +0200434 ...
435 registry:
436 secret:
437 registry01:
438 enabled: True
439 key: (get from `cat /root/.docker/config.json | base64`)
440 namespace: default
441 ...
442 control:
443 ...
444 service:
445 service01:
446 ...
447 image_pull_secretes: registry01
448 ...
449
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200450Kubernetes Service Definitions in pillars
451==========================================
452
453Following samples show how to generate kubernetes manifest as well and provide single tool for complete infrastructure management.
454
455Deployment manifest
456---------------------
marcoacdae7e2015-12-02 15:35:37 +0100457
458.. code-block:: yaml
459
460 salt:
461 control:
462 enabled: True
463 hostNetwork: True
464 service:
465 memcached:
466 privileged: True
467 service: memcached
468 role: server
469 type: LoadBalancer
470 replicas: 3
471 kind: Deployment
472 apiVersion: extensions/v1beta1
473 ports:
474 - port: 8774
475 name: nova-api
476 - port: 8775
477 name: nova-metadata
478 volume:
479 volume_name:
480 type: hostPath
481 mount: /certs
482 path: /etc/certs
483 container:
484 memcached:
485 image: memcached
486 tag:2
487 ports:
488 - port: 8774
489 name: nova-api
490 - port: 8775
491 name: nova-metadata
492 variables:
493 - name: HTTP_TLS_CERTIFICATE:
494 value: /certs/domain.crt
495 - name: HTTP_TLS_KEY
496 value: /certs/domain.key
497 volumes:
498 - name: /etc/certs
499 type: hostPath
500 mount: /certs
501 path: /etc/certs
502
marcobe30c8d2016-10-11 19:16:35 +0200503PetSet manifest
504---------------------
505
506.. code-block:: yaml
507
508 service:
509 memcached:
510 apiVersion: apps/v1alpha1
511 kind: PetSet
512 service_name: 'memcached'
513 container:
514 memcached:
515 ...
516
517
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200518Configmap
519---------
520
521You are able to create configmaps using support layer between formulas.
522It works simple, eg. in nova formula there's file ``meta/config.yml`` which
523defines config files used by that service and roles.
524
525Kubernetes formula is able to generate these files using custom pillar and
526grains structure. This way you are able to run docker images built by any way
527while still re-using your configuration management.
528
529Example pillar:
530
531.. code-block:: bash
532
533 kubernetes:
534 control:
Jakub Pavlika2779722016-11-25 15:35:26 +0100535 config_type: default|kubernetes # Output is yaml k8s or default single files
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200536 configmap:
537 nova-control:
538 grains:
539 # Alternate grains as OS running in container may differ from
540 # salt minion OS. Needed only if grains matters for config
541 # generation.
542 os_family: Debian
543 pillar:
544 # Generic pillar for nova controller
545 nova:
546 controller:
547 enabled: true
548 versionn: liberty
549 ...
550
551To tell which services supports config generation, you need to ensure pillar
552structure like this to determine support:
553
554.. code-block:: yaml
555
556 nova:
557 _support:
558 config:
559 enabled: true
560
marcod4d3dbd2016-09-27 11:36:40 +0200561initContainers
562--------------
563
564Example pillar:
565
566.. code-block:: bash
567
568 kubernetes:
569 control:
570 service:
571 memcached:
572 init_containers:
573 - name: test-mysql
574 image: busybox
575 command:
576 - sleep
577 - 3600
578 volumes:
579 - name: config
580 mount: /test
581 - name: test-memcached
582 image: busybox
583 command:
584 - sleep
585 - 3600
586 volumes:
587 - name: config
588 mount: /test
589
marcoee859d32016-11-07 11:04:57 +0100590Affinity
591--------
592
593podAffinity
594===========
595
596Example pillar:
597
598.. code-block:: bash
599
600 kubernetes:
601 control:
602 service:
603 memcached:
604 affinity:
605 pod_affinity:
606 name: podAffinity
607 expression:
608 label_selector:
609 name: labelSelector
610 selectors:
611 - key: app
612 value: memcached
613 topology_key: kubernetes.io/hostname
614
615podAntiAffinity
616===============
617
618Example pillar:
619
620.. code-block:: bash
621
622 kubernetes:
623 control:
624 service:
625 memcached:
626 affinity:
627 anti_affinity:
628 name: podAntiAffinity
629 expression:
630 label_selector:
631 name: labelSelector
632 selectors:
633 - key: app
634 value: opencontrail-control
635 topology_key: kubernetes.io/hostname
636
637nodeAffinity
638===============
639
640Example pillar:
641
642.. code-block:: bash
643
644 kubernetes:
645 control:
646 service:
647 memcached:
648 affinity:
649 node_affinity:
650 name: nodeAffinity
651 expression:
652 match_expressions:
653 name: matchExpressions
654 selectors:
655 - key: key
656 operator: In
657 values:
658 - value1
659 - value2
660
marcoacdae7e2015-12-02 15:35:37 +0100661Volumes
662-------
663
664hostPath
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200665==========
marcoacdae7e2015-12-02 15:35:37 +0100666
667.. code-block:: yaml
668
marcob469f882016-09-27 09:56:13 +0200669 service:
marcoacdae7e2015-12-02 15:35:37 +0100670 memcached:
marcob469f882016-09-27 09:56:13 +0200671 container:
672 memcached:
673 volumes:
674 - name: volume1
675 mountPath: /volume
676 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100677 ...
marcob469f882016-09-27 09:56:13 +0200678 volume:
679 volume1:
680 name: /etc/certs
681 type: hostPath
682 path: /etc/certs
marcoacdae7e2015-12-02 15:35:37 +0100683
684emptyDir
Ales Komarek688a04c2016-07-15 15:12:30 +0200685========
marcoacdae7e2015-12-02 15:35:37 +0100686
687.. code-block:: yaml
688
marcob469f882016-09-27 09:56:13 +0200689 service:
marcoacdae7e2015-12-02 15:35:37 +0100690 memcached:
marcob469f882016-09-27 09:56:13 +0200691 container:
692 memcached:
693 volumes:
694 - name: volume1
695 mountPath: /volume
696 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100697 ...
marcob469f882016-09-27 09:56:13 +0200698 volume:
699 volume1:
700 name: /etc/certs
701 type: emptyDir
702
703configMap
704=========
705
706.. code-block:: yaml
707
708 service:
709 memcached:
710 container:
711 memcached:
712 volumes:
713 - name: volume1
714 mountPath: /volume
715 readOnly: True
716 ...
717 volume:
718 volume1:
719 type: config_map
720 item:
721 configMap1:
722 key: config.conf
723 path: config.conf
724 configMap2:
725 key: policy.json
726 path: policy.json
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200727
marco0eda4fb2016-10-10 19:08:27 +0200728To mount single configuration file instead of whole directory:
729
730.. code-block:: yaml
731
732 service:
733 memcached:
734 container:
735 memcached:
736 volumes:
737 - name: volume1
738 mountPath: /volume/config.conf
739 sub_path: config.conf
740
marcofcc20d02016-10-10 09:56:12 +0200741Generating Jobs
742===============
743
744Example pillar:
745
746.. code-block:: yaml
747
748 kubernetes:
749 control:
750 job:
751 sleep:
752 job: sleep
753 restart_policy: Never
754 container:
755 sleep:
756 image: busybox
757 tag: latest
758 command:
759 - sleep
760 - "3600"
761
762Volumes and Variables can be used as the same way as during Deployment generation.
763
764Custom params:
765
766.. code-block:: yaml
767
768 kubernetes:
769 control:
770 job:
771 host_network: True
772 host_pid: True
773 container:
774 sleep:
775 privileged: True
776 node_selector:
777 key: node
778 value: one
779 image_pull_secretes: password
780
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200781Documentation and Bugs
Filip Pytloun06a55402016-08-12 14:53:30 +0200782======================
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200783
784To learn how to deploy OpenStack Salt, consult the documentation available
785online at:
786
787 https://wiki.openstack.org/wiki/OpenStackSalt
788
789In the unfortunate event that bugs are discovered, they should be reported to
790the appropriate bug tracker. If you obtained the software from a 3rd party
791operating system vendor, it is often wise to use their own bug tracker for
792reporting problems. In all other cases use the master OpenStack bug tracker,
793available at:
794
795 http://bugs.launchpad.net/openstack-salt
796
797Developers wishing to work on the OpenStack Salt project should always base
798their work on the latest formulas code, available from the master GIT
799repository at:
800
801 https://git.openstack.org/cgit/openstack/salt-formula-kubernetes
802
803Developers should also join the discussion on the IRC list, at:
804
805 https://wiki.openstack.org/wiki/Meetings/openstack-salt
Filip Pytloun06a55402016-08-12 14:53:30 +0200806
807Copyright and authors
808=====================
809
810(c) 2016 tcp cloud a.s.
811(c) 2016 OpenStack Foundation
Filip Pytlound06f6272017-02-02 13:02:03 +0100812
813Documentation and Bugs
814======================
815
816To learn how to install and update salt-formulas, consult the documentation
817available online at:
818
819 http://salt-formulas.readthedocs.io/
820
821In the unfortunate event that bugs are discovered, they should be reported to
822the appropriate issue tracker. Use Github issue tracker for specific salt
823formula:
824
825 https://github.com/salt-formulas/salt-formula-kubernetes/issues
826
827For feature requests, bug reports or blueprints affecting entire ecosystem,
828use Launchpad salt-formulas project:
829
830 https://launchpad.net/salt-formulas
831
832You can also join salt-formulas-users team and subscribe to mailing list:
833
834 https://launchpad.net/~salt-formulas-users
835
836Developers wishing to work on the salt-formulas projects should always base
837their work on master branch and submit pull request against specific formula.
838
839 https://github.com/salt-formulas/salt-formula-kubernetes
840
841Any questions or feedback is always welcome so feel free to join our IRC
842channel:
843
844 #salt-formulas @ irc.freenode.net