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