blob: 16f967b434dc7fc9c3b1b0d436281d8ea9fdb43c [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
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200196Kubernetes with OpenContrail network plugin
197------------------------------------------------
marcoacdae7e2015-12-02 15:35:37 +0100198
199On Master:
200
201.. code-block:: yaml
202
203 kubernetes:
204 master:
205 network:
206 engine: opencontrail
207 host: 10.0.170.70
208 port: 8082
209 default_domain: default-domain
210 default_project: default-domain:default-project
211 public_network: default-domain:default-project:Public
212 public_ip_range: 185.22.97.128/26
213 private_ip_range: 10.150.0.0/16
214 service_cluster_ip_range: 10.254.0.0/16
215 network_label: name
216 service_label: uses
217 cluster_service: kube-system/default
218 network_manager:
219 image: pupapaik/opencontrail-kube-network-manager
220 tag: release-1.1-jpa-final-1
221
222On pools:
223
224.. code-block:: yaml
225
226 kubernetes:
227 pool:
228 network:
229 engine: opencontrail
230
Jakub Pavlik1cfc1fe2016-07-25 11:01:52 +0200231Kubernetes control plane running in systemd
232-------------------------------------------
233
234By 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.
235
236.. code-block:: yaml
237
238 kubernetes:
239 master:
240 container: false
241
242 kubernetes:
243 pool:
244 container: false
245
marco055ff852016-07-27 15:22:33 +0200246Because k8s services run under kube user without root privileges, there is need to change secure port for apiserver.
247
248.. code-block:: yaml
249
250 kubernetes:
251 master:
252 apiserver:
253 secure_port: 8081
254
marcoacdae7e2015-12-02 15:35:37 +0100255Kubernetes with Flannel
256-----------------------
257
258On Master:
259
260.. code-block:: yaml
261
262 kubernetes:
263 master:
264 network:
265 engine: flannel
Jakub Pavlik7e985322016-07-17 13:16:15 +0200266 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200267 etcd:
268 members:
269 - host: 10.0.175.101
270 port: 4001
271 - host: 10.0.175.102
272 port: 4001
273 - host: 10.0.175.103
274 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100275 common:
276 network:
277 engine: flannel
278
279On pools:
280
281.. code-block:: yaml
282
283 kubernetes:
284 pool:
285 network:
286 engine: flannel
marcoa05621f2016-07-14 10:35:24 +0200287 etcd:
288 members:
289 - host: 10.0.175.101
290 port: 4001
291 - host: 10.0.175.102
292 port: 4001
293 - host: 10.0.175.103
294 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100295 common:
296 network:
297 engine: flannel
298
299Kubernetes with Calico
300-----------------------
301
302On Master:
303
304.. code-block:: yaml
305
306 kubernetes:
307 master:
308 network:
309 engine: calico
Jakub Pavlik7e985322016-07-17 13:16:15 +0200310 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200311 etcd:
312 members:
313 - host: 10.0.175.101
314 port: 4001
315 - host: 10.0.175.102
316 port: 4001
317 - host: 10.0.175.103
318 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100319
320On pools:
321
322.. code-block:: yaml
323
324 kubernetes:
325 pool:
326 network:
327 engine: calico
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
Tomáš Kukrál34c59362017-03-01 14:00:37 +0100337Running with secured etcd:
338
339.. code-block:: yaml
340
341 kubernetes:
342 pool:
343 network:
344 engine: calico
345 etcd:
346 ssl:
347 enabled: true
348 master:
349 network:
350 engine: calico
351 etcd:
352 ssl:
353 enabled: true
354
Tomáš Kukrál7e91a942017-03-23 16:02:52 +0100355Enable Prometheus metrics in Felix
356
357.. code-block:: yaml
358
359 kubernetes:
360 pool:
361 network:
362 prometheus:
363 enabled: true
364 master:
365 network:
366 prometheus:
367 enabled: true
368
Jakub Pavlik7e985322016-07-17 13:16:15 +0200369Post deployment configuration
370
371.. code-block:: bash
Jakub Pavlik232833c2016-07-17 13:21:00 +0200372
Jakub Pavlik7e985322016-07-17 13:16:15 +0200373 # set ETCD
374 export ETCD_AUTHORITY=10.0.111.201:4001
375
376 # Set NAT for pods subnet
377 calicoctl pool add 192.168.0.0/16 --nat-outgoing
378
379 # Status commands
380 calicoctl status
381 calicoctl node show
382
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200383Kubernetes with GlusterFS for storage
384---------------------------------------------
385
386.. code-block:: yaml
387
388 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100389 master:
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200390 ...
391 storage:
392 engine: glusterfs
393 port: 24007
394 members:
395 - host: 10.0.175.101
396 port: 24007
397 - host: 10.0.175.102
398 port: 24007
399 - host: 10.0.175.103
400 port: 24007
401 ...
402
marco45fc1b72016-07-02 16:11:18 +0200403Kubernetes namespaces
404---------------------
405
406Create namespace:
407
408.. code-block:: yaml
409
410 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100411 master:
marco45fc1b72016-07-02 16:11:18 +0200412 ...
413 namespace:
414 kube-system:
415 enabled: True
416 namespace2:
417 enabled: True
418 namespace3:
419 enabled: False
420 ...
421
422Kubernetes labels
423-----------------
424
Marek Celoud901020b2017-01-27 14:51:41 +0100425Label node:
marco45fc1b72016-07-02 16:11:18 +0200426
427.. code-block:: yaml
428
Marek Celoud901020b2017-01-27 14:51:41 +0100429 kubernetes:
430 master:
431 label:
432 label01:
433 value: value01
434 node: node01
435 enabled: true
436 key: key01
marco45fc1b72016-07-02 16:11:18 +0200437 ...
marco45fc1b72016-07-02 16:11:18 +0200438
marcof7efecb2016-07-16 16:13:37 +0200439Pull images from private registries
440-----------------------------------
441
442.. code-block:: yaml
443
444 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100445 master:
marcof7efecb2016-07-16 16:13:37 +0200446 ...
447 registry:
448 secret:
449 registry01:
450 enabled: True
451 key: (get from `cat /root/.docker/config.json | base64`)
452 namespace: default
453 ...
454 control:
455 ...
456 service:
457 service01:
458 ...
459 image_pull_secretes: registry01
460 ...
461
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200462Kubernetes Service Definitions in pillars
463==========================================
464
465Following samples show how to generate kubernetes manifest as well and provide single tool for complete infrastructure management.
466
467Deployment manifest
468---------------------
marcoacdae7e2015-12-02 15:35:37 +0100469
470.. code-block:: yaml
471
472 salt:
473 control:
474 enabled: True
475 hostNetwork: True
476 service:
477 memcached:
478 privileged: True
479 service: memcached
480 role: server
481 type: LoadBalancer
482 replicas: 3
483 kind: Deployment
484 apiVersion: extensions/v1beta1
485 ports:
486 - port: 8774
487 name: nova-api
488 - port: 8775
489 name: nova-metadata
490 volume:
491 volume_name:
492 type: hostPath
493 mount: /certs
494 path: /etc/certs
495 container:
496 memcached:
497 image: memcached
498 tag:2
499 ports:
500 - port: 8774
501 name: nova-api
502 - port: 8775
503 name: nova-metadata
504 variables:
505 - name: HTTP_TLS_CERTIFICATE:
506 value: /certs/domain.crt
507 - name: HTTP_TLS_KEY
508 value: /certs/domain.key
509 volumes:
510 - name: /etc/certs
511 type: hostPath
512 mount: /certs
513 path: /etc/certs
514
marcobe30c8d2016-10-11 19:16:35 +0200515PetSet manifest
516---------------------
517
518.. code-block:: yaml
519
520 service:
521 memcached:
522 apiVersion: apps/v1alpha1
523 kind: PetSet
524 service_name: 'memcached'
525 container:
526 memcached:
527 ...
528
529
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200530Configmap
531---------
532
533You are able to create configmaps using support layer between formulas.
534It works simple, eg. in nova formula there's file ``meta/config.yml`` which
535defines config files used by that service and roles.
536
537Kubernetes formula is able to generate these files using custom pillar and
538grains structure. This way you are able to run docker images built by any way
539while still re-using your configuration management.
540
541Example pillar:
542
543.. code-block:: bash
544
545 kubernetes:
546 control:
Jakub Pavlika2779722016-11-25 15:35:26 +0100547 config_type: default|kubernetes # Output is yaml k8s or default single files
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200548 configmap:
549 nova-control:
550 grains:
551 # Alternate grains as OS running in container may differ from
552 # salt minion OS. Needed only if grains matters for config
553 # generation.
554 os_family: Debian
555 pillar:
556 # Generic pillar for nova controller
557 nova:
558 controller:
559 enabled: true
560 versionn: liberty
561 ...
562
563To tell which services supports config generation, you need to ensure pillar
564structure like this to determine support:
565
566.. code-block:: yaml
567
568 nova:
569 _support:
570 config:
571 enabled: true
572
marcod4d3dbd2016-09-27 11:36:40 +0200573initContainers
574--------------
575
576Example pillar:
577
578.. code-block:: bash
579
580 kubernetes:
581 control:
582 service:
583 memcached:
584 init_containers:
585 - name: test-mysql
586 image: busybox
587 command:
588 - sleep
589 - 3600
590 volumes:
591 - name: config
592 mount: /test
593 - name: test-memcached
594 image: busybox
595 command:
596 - sleep
597 - 3600
598 volumes:
599 - name: config
600 mount: /test
601
marcoee859d32016-11-07 11:04:57 +0100602Affinity
603--------
604
605podAffinity
606===========
607
608Example pillar:
609
610.. code-block:: bash
611
612 kubernetes:
613 control:
614 service:
615 memcached:
616 affinity:
617 pod_affinity:
618 name: podAffinity
619 expression:
620 label_selector:
621 name: labelSelector
622 selectors:
623 - key: app
624 value: memcached
625 topology_key: kubernetes.io/hostname
626
627podAntiAffinity
628===============
629
630Example pillar:
631
632.. code-block:: bash
633
634 kubernetes:
635 control:
636 service:
637 memcached:
638 affinity:
639 anti_affinity:
640 name: podAntiAffinity
641 expression:
642 label_selector:
643 name: labelSelector
644 selectors:
645 - key: app
646 value: opencontrail-control
647 topology_key: kubernetes.io/hostname
648
649nodeAffinity
650===============
651
652Example pillar:
653
654.. code-block:: bash
655
656 kubernetes:
657 control:
658 service:
659 memcached:
660 affinity:
661 node_affinity:
662 name: nodeAffinity
663 expression:
664 match_expressions:
665 name: matchExpressions
666 selectors:
667 - key: key
668 operator: In
669 values:
670 - value1
671 - value2
672
marcoacdae7e2015-12-02 15:35:37 +0100673Volumes
674-------
675
676hostPath
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200677==========
marcoacdae7e2015-12-02 15:35:37 +0100678
679.. code-block:: yaml
680
marcob469f882016-09-27 09:56:13 +0200681 service:
marcoacdae7e2015-12-02 15:35:37 +0100682 memcached:
marcob469f882016-09-27 09:56:13 +0200683 container:
684 memcached:
685 volumes:
686 - name: volume1
687 mountPath: /volume
688 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100689 ...
marcob469f882016-09-27 09:56:13 +0200690 volume:
691 volume1:
692 name: /etc/certs
693 type: hostPath
694 path: /etc/certs
marcoacdae7e2015-12-02 15:35:37 +0100695
696emptyDir
Ales Komarek688a04c2016-07-15 15:12:30 +0200697========
marcoacdae7e2015-12-02 15:35:37 +0100698
699.. code-block:: yaml
700
marcob469f882016-09-27 09:56:13 +0200701 service:
marcoacdae7e2015-12-02 15:35:37 +0100702 memcached:
marcob469f882016-09-27 09:56:13 +0200703 container:
704 memcached:
705 volumes:
706 - name: volume1
707 mountPath: /volume
708 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100709 ...
marcob469f882016-09-27 09:56:13 +0200710 volume:
711 volume1:
712 name: /etc/certs
713 type: emptyDir
714
715configMap
716=========
717
718.. code-block:: yaml
719
720 service:
721 memcached:
722 container:
723 memcached:
724 volumes:
725 - name: volume1
726 mountPath: /volume
727 readOnly: True
728 ...
729 volume:
730 volume1:
731 type: config_map
732 item:
733 configMap1:
734 key: config.conf
735 path: config.conf
736 configMap2:
737 key: policy.json
738 path: policy.json
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200739
marco0eda4fb2016-10-10 19:08:27 +0200740To mount single configuration file instead of whole directory:
741
742.. code-block:: yaml
743
744 service:
745 memcached:
746 container:
747 memcached:
748 volumes:
749 - name: volume1
750 mountPath: /volume/config.conf
751 sub_path: config.conf
752
marcofcc20d02016-10-10 09:56:12 +0200753Generating Jobs
754===============
755
756Example pillar:
757
758.. code-block:: yaml
759
760 kubernetes:
761 control:
762 job:
763 sleep:
764 job: sleep
765 restart_policy: Never
766 container:
767 sleep:
768 image: busybox
769 tag: latest
770 command:
771 - sleep
772 - "3600"
773
774Volumes and Variables can be used as the same way as during Deployment generation.
775
776Custom params:
777
778.. code-block:: yaml
779
780 kubernetes:
781 control:
782 job:
783 host_network: True
784 host_pid: True
785 container:
786 sleep:
787 privileged: True
788 node_selector:
789 key: node
790 value: one
791 image_pull_secretes: password
792
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200793Documentation and Bugs
Filip Pytloun06a55402016-08-12 14:53:30 +0200794======================
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200795
796To learn how to deploy OpenStack Salt, consult the documentation available
797online at:
798
799 https://wiki.openstack.org/wiki/OpenStackSalt
800
801In the unfortunate event that bugs are discovered, they should be reported to
802the appropriate bug tracker. If you obtained the software from a 3rd party
803operating system vendor, it is often wise to use their own bug tracker for
804reporting problems. In all other cases use the master OpenStack bug tracker,
805available at:
806
807 http://bugs.launchpad.net/openstack-salt
808
809Developers wishing to work on the OpenStack Salt project should always base
810their work on the latest formulas code, available from the master GIT
811repository at:
812
813 https://git.openstack.org/cgit/openstack/salt-formula-kubernetes
814
815Developers should also join the discussion on the IRC list, at:
816
817 https://wiki.openstack.org/wiki/Meetings/openstack-salt
Filip Pytloun06a55402016-08-12 14:53:30 +0200818
819Copyright and authors
820=====================
821
822(c) 2016 tcp cloud a.s.
823(c) 2016 OpenStack Foundation
Filip Pytlound06f6272017-02-02 13:02:03 +0100824
825Documentation and Bugs
826======================
827
828To learn how to install and update salt-formulas, consult the documentation
829available online at:
830
831 http://salt-formulas.readthedocs.io/
832
833In the unfortunate event that bugs are discovered, they should be reported to
834the appropriate issue tracker. Use Github issue tracker for specific salt
835formula:
836
837 https://github.com/salt-formulas/salt-formula-kubernetes/issues
838
839For feature requests, bug reports or blueprints affecting entire ecosystem,
840use Launchpad salt-formulas project:
841
842 https://launchpad.net/salt-formulas
843
844You can also join salt-formulas-users team and subscribe to mailing list:
845
846 https://launchpad.net/~salt-formulas-users
847
848Developers wishing to work on the salt-formulas projects should always base
849their work on master branch and submit pull request against specific formula.
850
851 https://github.com/salt-formulas/salt-formula-kubernetes
852
853Any questions or feedback is always welcome so feel free to join our IRC
854channel:
855
856 #salt-formulas @ irc.freenode.net