blob: f34f87701b7373f0b1721eb71338cabe5c892889 [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álaff35262017-04-18 12:37:45 +020060Enable autoscaler for dns addon. Poll period can be skipped.
61
62.. code-block:: yaml
63
64 kubernetes:
65 master:
66 addons:
67 dns:
68 domain: cluster.local
69 enabled: true
70 replicas: 1
71 server: 10.254.0.10
72 autoscaler:
73 enabled: true
74 poll-period-seconds: 60
75
76
Tomáš Kukrál6ef3f892017-02-15 12:02:22 +010077Pass aditional parameters to daemons:
78
79.. code-block:: yaml
80
81 parameters:
82 kubernetes:
83 master:
84 apiserver:
85 daemon_opts:
86 storage-backend: pigeon
87 controller_manager:
88 daemon_opts:
89 log-dir: /dev/nulL
90 pool:
91 kubelet:
92 daemon_opts:
93 max-pods: "6"
94
Tomáš Kukrál189da4b2017-01-18 14:30:09 +010095
Ales Komarek688a04c2016-07-15 15:12:30 +020096Containers on pool definitions in pool.service.local
97
Jakub Pavlik7e985322016-07-17 13:16:15 +020098.. code-block:: yaml
99
100 parameters:
101 kubernetes:
102 pool:
103 service:
104 local:
105 enabled: False
106 service: libvirt
107 cluster: openstack-compute
108 namespace: default
109 role: ${linux:system:name}
110 type: LoadBalancer
111 kind: Deployment
112 apiVersion: extensions/v1beta1
113 replicas: 1
114 host_pid: True
115 nodeSelector:
116 - key: openstack
117 value: ${linux:system:name}
118 hostNetwork: True
119 container:
120 libvirt-compute:
121 privileged: True
122 image: ${_param:docker_repository}/libvirt-compute
123 tag: ${_param:openstack_container_tag}
Ales Komarek688a04c2016-07-15 15:12:30 +0200124
125Master definition
126
marcoacdae7e2015-12-02 15:35:37 +0100127.. code-block:: yaml
128
129 kubernetes:
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200130 master:
131 addons:
132 dns:
133 domain: cluster.local
134 enabled: true
135 replicas: 1
136 server: 10.254.0.10
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200137 admin:
138 password: password
139 username: admin
140 apiserver:
141 address: 10.0.175.100
Swann Croisetff97efc2017-02-23 13:32:33 +0100142 secure_port: 443
143 insecure_address: 127.0.0.1
144 insecure_port: 8080
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200145 ca: kubernetes
146 enabled: true
147 etcd:
148 host: 127.0.0.1
149 members:
150 - host: 10.0.175.100
151 name: node040
152 name: node040
153 token: ca939ec9c2a17b0786f6d411fe019e9b
154 kubelet:
155 allow_privileged: true
156 network:
157 engine: calico
158 hash: fb5e30ebe6154911a66ec3fb5f1195b2
159 private_ip_range: 10.150.0.0/16
160 version: v0.19.0
161 service_addresses: 10.254.0.0/16
162 storage:
163 engine: glusterfs
164 members:
165 - host: 10.0.175.101
166 port: 24007
167 - host: 10.0.175.102
168 port: 24007
169 - host: 10.0.175.103
170 port: 24007
171 port: 24007
172 token:
173 admin: DFvQ8GJ9JD4fKNfuyEddw3rjnFTkUKsv
174 controller_manager: EreGh6AnWf8DxH8cYavB2zS029PUi7vx
175 dns: RAFeVSE4UvsCz4gk3KYReuOI5jsZ1Xt3
176 kube_proxy: DFvQ8GelB7afH3wClC9romaMPhquyyEe
177 kubelet: 7bN5hJ9JD4fKjnFTkUKsvVNfuyEddw3r
178 logging: MJkXKdbgqRmTHSa2ykTaOaMykgO6KcEf
179 monitoring: hnsj0XqABgrSww7Nqo7UVTSZLJUt2XRd
180 scheduler: HY1UUxEPpmjW4a1dDLGIANYQp1nZkLDk
181 version: v1.2.4
182
marcoacdae7e2015-12-02 15:35:37 +0100183
184 kubernetes:
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200185 pool:
186 address: 0.0.0.0
187 allow_privileged: true
188 ca: kubernetes
189 cluster_dns: 10.254.0.10
190 cluster_domain: cluster.local
191 enabled: true
192 kubelet:
193 allow_privileged: true
194 config: /etc/kubernetes/manifests
195 frequency: 5s
196 master:
197 apiserver:
198 members:
199 - host: 10.0.175.100
200 etcd:
201 members:
202 - host: 10.0.175.100
203 host: 10.0.175.100
204 network:
205 engine: calico
206 hash: fb5e30ebe6154911a66ec3fb5f1195b2
207 version: v0.19.0
208 token:
209 kube_proxy: DFvQ8GelB7afH3wClC9romaMPhquyyEe
210 kubelet: 7bN5hJ9JD4fKjnFTkUKsvVNfuyEddw3r
211 version: v1.2.4
marcoacdae7e2015-12-02 15:35:37 +0100212
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200213Kubernetes with OpenContrail network plugin
214------------------------------------------------
marcoacdae7e2015-12-02 15:35:37 +0100215
216On Master:
217
218.. code-block:: yaml
219
220 kubernetes:
221 master:
222 network:
223 engine: opencontrail
224 host: 10.0.170.70
225 port: 8082
226 default_domain: default-domain
227 default_project: default-domain:default-project
228 public_network: default-domain:default-project:Public
229 public_ip_range: 185.22.97.128/26
230 private_ip_range: 10.150.0.0/16
231 service_cluster_ip_range: 10.254.0.0/16
232 network_label: name
233 service_label: uses
234 cluster_service: kube-system/default
235 network_manager:
236 image: pupapaik/opencontrail-kube-network-manager
237 tag: release-1.1-jpa-final-1
238
239On pools:
240
241.. code-block:: yaml
242
243 kubernetes:
244 pool:
245 network:
246 engine: opencontrail
247
Jakub Pavlik1cfc1fe2016-07-25 11:01:52 +0200248Kubernetes control plane running in systemd
249-------------------------------------------
250
251By 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.
252
253.. code-block:: yaml
254
255 kubernetes:
256 master:
257 container: false
258
259 kubernetes:
260 pool:
261 container: false
262
marco055ff852016-07-27 15:22:33 +0200263Because k8s services run under kube user without root privileges, there is need to change secure port for apiserver.
264
265.. code-block:: yaml
266
267 kubernetes:
268 master:
269 apiserver:
270 secure_port: 8081
271
marcoacdae7e2015-12-02 15:35:37 +0100272Kubernetes with Flannel
273-----------------------
274
275On Master:
276
277.. code-block:: yaml
278
279 kubernetes:
280 master:
281 network:
282 engine: flannel
Jakub Pavlik7e985322016-07-17 13:16:15 +0200283 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200284 etcd:
285 members:
286 - host: 10.0.175.101
287 port: 4001
288 - host: 10.0.175.102
289 port: 4001
290 - host: 10.0.175.103
291 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100292 common:
293 network:
294 engine: flannel
295
296On pools:
297
298.. code-block:: yaml
299
300 kubernetes:
301 pool:
302 network:
303 engine: flannel
marcoa05621f2016-07-14 10:35:24 +0200304 etcd:
305 members:
306 - host: 10.0.175.101
307 port: 4001
308 - host: 10.0.175.102
309 port: 4001
310 - host: 10.0.175.103
311 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100312 common:
313 network:
314 engine: flannel
315
316Kubernetes with Calico
317-----------------------
318
319On Master:
320
321.. code-block:: yaml
322
323 kubernetes:
324 master:
325 network:
326 engine: calico
Jakub Pavlik7e985322016-07-17 13:16:15 +0200327 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200328 etcd:
329 members:
330 - host: 10.0.175.101
331 port: 4001
332 - host: 10.0.175.102
333 port: 4001
334 - host: 10.0.175.103
335 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100336
337On pools:
338
339.. code-block:: yaml
340
341 kubernetes:
342 pool:
343 network:
344 engine: calico
marcoa05621f2016-07-14 10:35:24 +0200345 etcd:
346 members:
347 - host: 10.0.175.101
348 port: 4001
349 - host: 10.0.175.102
350 port: 4001
351 - host: 10.0.175.103
352 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100353
Tomáš Kukrál34c59362017-03-01 14:00:37 +0100354Running with secured etcd:
355
356.. code-block:: yaml
357
358 kubernetes:
359 pool:
360 network:
361 engine: calico
362 etcd:
363 ssl:
364 enabled: true
365 master:
366 network:
367 engine: calico
368 etcd:
369 ssl:
370 enabled: true
371
Tomáš Kukrál7e91a942017-03-23 16:02:52 +0100372Enable Prometheus metrics in Felix
373
374.. code-block:: yaml
375
376 kubernetes:
377 pool:
378 network:
379 prometheus:
380 enabled: true
381 master:
382 network:
383 prometheus:
384 enabled: true
385
Jakub Pavlik7e985322016-07-17 13:16:15 +0200386Post deployment configuration
387
388.. code-block:: bash
Jakub Pavlik232833c2016-07-17 13:21:00 +0200389
Jakub Pavlik7e985322016-07-17 13:16:15 +0200390 # set ETCD
391 export ETCD_AUTHORITY=10.0.111.201:4001
392
393 # Set NAT for pods subnet
394 calicoctl pool add 192.168.0.0/16 --nat-outgoing
395
396 # Status commands
397 calicoctl status
398 calicoctl node show
399
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200400Kubernetes with GlusterFS for storage
401---------------------------------------------
402
403.. code-block:: yaml
404
405 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100406 master:
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200407 ...
408 storage:
409 engine: glusterfs
410 port: 24007
411 members:
412 - host: 10.0.175.101
413 port: 24007
414 - host: 10.0.175.102
415 port: 24007
416 - host: 10.0.175.103
417 port: 24007
418 ...
419
marco45fc1b72016-07-02 16:11:18 +0200420Kubernetes namespaces
421---------------------
422
423Create namespace:
424
425.. code-block:: yaml
426
427 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100428 master:
marco45fc1b72016-07-02 16:11:18 +0200429 ...
430 namespace:
431 kube-system:
432 enabled: True
433 namespace2:
434 enabled: True
435 namespace3:
436 enabled: False
437 ...
438
439Kubernetes labels
440-----------------
441
Marek Celoud901020b2017-01-27 14:51:41 +0100442Label node:
marco45fc1b72016-07-02 16:11:18 +0200443
444.. code-block:: yaml
445
Marek Celoud901020b2017-01-27 14:51:41 +0100446 kubernetes:
447 master:
448 label:
449 label01:
450 value: value01
451 node: node01
452 enabled: true
453 key: key01
marco45fc1b72016-07-02 16:11:18 +0200454 ...
marco45fc1b72016-07-02 16:11:18 +0200455
marcof7efecb2016-07-16 16:13:37 +0200456Pull images from private registries
457-----------------------------------
458
459.. code-block:: yaml
460
461 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100462 master:
marcof7efecb2016-07-16 16:13:37 +0200463 ...
464 registry:
465 secret:
466 registry01:
467 enabled: True
468 key: (get from `cat /root/.docker/config.json | base64`)
469 namespace: default
470 ...
471 control:
472 ...
473 service:
474 service01:
475 ...
476 image_pull_secretes: registry01
477 ...
478
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200479Kubernetes Service Definitions in pillars
480==========================================
481
482Following samples show how to generate kubernetes manifest as well and provide single tool for complete infrastructure management.
483
484Deployment manifest
485---------------------
marcoacdae7e2015-12-02 15:35:37 +0100486
487.. code-block:: yaml
488
489 salt:
490 control:
491 enabled: True
492 hostNetwork: True
493 service:
494 memcached:
495 privileged: True
496 service: memcached
497 role: server
498 type: LoadBalancer
499 replicas: 3
500 kind: Deployment
501 apiVersion: extensions/v1beta1
502 ports:
503 - port: 8774
504 name: nova-api
505 - port: 8775
506 name: nova-metadata
507 volume:
508 volume_name:
509 type: hostPath
510 mount: /certs
511 path: /etc/certs
512 container:
513 memcached:
514 image: memcached
515 tag:2
516 ports:
517 - port: 8774
518 name: nova-api
519 - port: 8775
520 name: nova-metadata
521 variables:
522 - name: HTTP_TLS_CERTIFICATE:
523 value: /certs/domain.crt
524 - name: HTTP_TLS_KEY
525 value: /certs/domain.key
526 volumes:
527 - name: /etc/certs
528 type: hostPath
529 mount: /certs
530 path: /etc/certs
531
marcobe30c8d2016-10-11 19:16:35 +0200532PetSet manifest
533---------------------
534
535.. code-block:: yaml
536
537 service:
538 memcached:
539 apiVersion: apps/v1alpha1
540 kind: PetSet
541 service_name: 'memcached'
542 container:
543 memcached:
544 ...
545
546
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200547Configmap
548---------
549
550You are able to create configmaps using support layer between formulas.
551It works simple, eg. in nova formula there's file ``meta/config.yml`` which
552defines config files used by that service and roles.
553
554Kubernetes formula is able to generate these files using custom pillar and
555grains structure. This way you are able to run docker images built by any way
556while still re-using your configuration management.
557
558Example pillar:
559
560.. code-block:: bash
561
562 kubernetes:
563 control:
Jakub Pavlika2779722016-11-25 15:35:26 +0100564 config_type: default|kubernetes # Output is yaml k8s or default single files
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200565 configmap:
566 nova-control:
567 grains:
568 # Alternate grains as OS running in container may differ from
569 # salt minion OS. Needed only if grains matters for config
570 # generation.
571 os_family: Debian
572 pillar:
573 # Generic pillar for nova controller
574 nova:
575 controller:
576 enabled: true
577 versionn: liberty
578 ...
579
580To tell which services supports config generation, you need to ensure pillar
581structure like this to determine support:
582
583.. code-block:: yaml
584
585 nova:
586 _support:
587 config:
588 enabled: true
589
marcod4d3dbd2016-09-27 11:36:40 +0200590initContainers
591--------------
592
593Example pillar:
594
595.. code-block:: bash
596
597 kubernetes:
598 control:
599 service:
600 memcached:
601 init_containers:
602 - name: test-mysql
603 image: busybox
604 command:
605 - sleep
606 - 3600
607 volumes:
608 - name: config
609 mount: /test
610 - name: test-memcached
611 image: busybox
612 command:
613 - sleep
614 - 3600
615 volumes:
616 - name: config
617 mount: /test
618
marcoee859d32016-11-07 11:04:57 +0100619Affinity
620--------
621
622podAffinity
623===========
624
625Example pillar:
626
627.. code-block:: bash
628
629 kubernetes:
630 control:
631 service:
632 memcached:
633 affinity:
634 pod_affinity:
635 name: podAffinity
636 expression:
637 label_selector:
638 name: labelSelector
639 selectors:
640 - key: app
641 value: memcached
642 topology_key: kubernetes.io/hostname
643
644podAntiAffinity
645===============
646
647Example pillar:
648
649.. code-block:: bash
650
651 kubernetes:
652 control:
653 service:
654 memcached:
655 affinity:
656 anti_affinity:
657 name: podAntiAffinity
658 expression:
659 label_selector:
660 name: labelSelector
661 selectors:
662 - key: app
663 value: opencontrail-control
664 topology_key: kubernetes.io/hostname
665
666nodeAffinity
667===============
668
669Example pillar:
670
671.. code-block:: bash
672
673 kubernetes:
674 control:
675 service:
676 memcached:
677 affinity:
678 node_affinity:
679 name: nodeAffinity
680 expression:
681 match_expressions:
682 name: matchExpressions
683 selectors:
684 - key: key
685 operator: In
686 values:
687 - value1
688 - value2
689
marcoacdae7e2015-12-02 15:35:37 +0100690Volumes
691-------
692
693hostPath
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200694==========
marcoacdae7e2015-12-02 15:35:37 +0100695
696.. code-block:: yaml
697
marcob469f882016-09-27 09:56:13 +0200698 service:
marcoacdae7e2015-12-02 15:35:37 +0100699 memcached:
marcob469f882016-09-27 09:56:13 +0200700 container:
701 memcached:
702 volumes:
703 - name: volume1
704 mountPath: /volume
705 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100706 ...
marcob469f882016-09-27 09:56:13 +0200707 volume:
708 volume1:
709 name: /etc/certs
710 type: hostPath
711 path: /etc/certs
marcoacdae7e2015-12-02 15:35:37 +0100712
713emptyDir
Ales Komarek688a04c2016-07-15 15:12:30 +0200714========
marcoacdae7e2015-12-02 15:35:37 +0100715
716.. code-block:: yaml
717
marcob469f882016-09-27 09:56:13 +0200718 service:
marcoacdae7e2015-12-02 15:35:37 +0100719 memcached:
marcob469f882016-09-27 09:56:13 +0200720 container:
721 memcached:
722 volumes:
723 - name: volume1
724 mountPath: /volume
725 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100726 ...
marcob469f882016-09-27 09:56:13 +0200727 volume:
728 volume1:
729 name: /etc/certs
730 type: emptyDir
731
732configMap
733=========
734
735.. code-block:: yaml
736
737 service:
738 memcached:
739 container:
740 memcached:
741 volumes:
742 - name: volume1
743 mountPath: /volume
744 readOnly: True
745 ...
746 volume:
747 volume1:
748 type: config_map
749 item:
750 configMap1:
751 key: config.conf
752 path: config.conf
753 configMap2:
754 key: policy.json
755 path: policy.json
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200756
marco0eda4fb2016-10-10 19:08:27 +0200757To mount single configuration file instead of whole directory:
758
759.. code-block:: yaml
760
761 service:
762 memcached:
763 container:
764 memcached:
765 volumes:
766 - name: volume1
767 mountPath: /volume/config.conf
768 sub_path: config.conf
769
marcofcc20d02016-10-10 09:56:12 +0200770Generating Jobs
771===============
772
773Example pillar:
774
775.. code-block:: yaml
776
777 kubernetes:
778 control:
779 job:
780 sleep:
781 job: sleep
782 restart_policy: Never
783 container:
784 sleep:
785 image: busybox
786 tag: latest
787 command:
788 - sleep
789 - "3600"
790
791Volumes and Variables can be used as the same way as during Deployment generation.
792
793Custom params:
794
795.. code-block:: yaml
796
797 kubernetes:
798 control:
799 job:
800 host_network: True
801 host_pid: True
802 container:
803 sleep:
804 privileged: True
805 node_selector:
806 key: node
807 value: one
808 image_pull_secretes: password
809
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200810Documentation and Bugs
Filip Pytloun06a55402016-08-12 14:53:30 +0200811======================
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200812
813To learn how to deploy OpenStack Salt, consult the documentation available
814online at:
815
816 https://wiki.openstack.org/wiki/OpenStackSalt
817
818In the unfortunate event that bugs are discovered, they should be reported to
819the appropriate bug tracker. If you obtained the software from a 3rd party
820operating system vendor, it is often wise to use their own bug tracker for
821reporting problems. In all other cases use the master OpenStack bug tracker,
822available at:
823
824 http://bugs.launchpad.net/openstack-salt
825
826Developers wishing to work on the OpenStack Salt project should always base
827their work on the latest formulas code, available from the master GIT
828repository at:
829
830 https://git.openstack.org/cgit/openstack/salt-formula-kubernetes
831
832Developers should also join the discussion on the IRC list, at:
833
834 https://wiki.openstack.org/wiki/Meetings/openstack-salt
Filip Pytloun06a55402016-08-12 14:53:30 +0200835
836Copyright and authors
837=====================
838
839(c) 2016 tcp cloud a.s.
840(c) 2016 OpenStack Foundation
Filip Pytlound06f6272017-02-02 13:02:03 +0100841
842Documentation and Bugs
843======================
844
845To learn how to install and update salt-formulas, consult the documentation
846available online at:
847
848 http://salt-formulas.readthedocs.io/
849
850In the unfortunate event that bugs are discovered, they should be reported to
851the appropriate issue tracker. Use Github issue tracker for specific salt
852formula:
853
854 https://github.com/salt-formulas/salt-formula-kubernetes/issues
855
856For feature requests, bug reports or blueprints affecting entire ecosystem,
857use Launchpad salt-formulas project:
858
859 https://launchpad.net/salt-formulas
860
861You can also join salt-formulas-users team and subscribe to mailing list:
862
863 https://launchpad.net/~salt-formulas-users
864
865Developers wishing to work on the salt-formulas projects should always base
866their work on master branch and submit pull request against specific formula.
867
868 https://github.com/salt-formulas/salt-formula-kubernetes
869
870Any questions or feedback is always welcome so feel free to join our IRC
871channel:
872
873 #salt-formulas @ irc.freenode.net