blob: 7f38048af86431843a4aa022244361ae1bd70cf8 [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:
27 image: gcr.io/google_containers/hyperkube:v1.4.6
28 pool:
29 network:
30 calicoctl:
31 image: calico/ctl
32 cni:
33 image: calico/cni
34
Tomáš Kukrál6ef3f892017-02-15 12:02:22 +010035Pass aditional parameters to daemons:
36
37.. code-block:: yaml
38
39 parameters:
40 kubernetes:
41 master:
42 apiserver:
43 daemon_opts:
44 storage-backend: pigeon
45 controller_manager:
46 daemon_opts:
47 log-dir: /dev/nulL
48 pool:
49 kubelet:
50 daemon_opts:
51 max-pods: "6"
52
Tomáš Kukrál189da4b2017-01-18 14:30:09 +010053
Ales Komarek688a04c2016-07-15 15:12:30 +020054Containers on pool definitions in pool.service.local
55
Jakub Pavlik7e985322016-07-17 13:16:15 +020056.. code-block:: yaml
57
58 parameters:
59 kubernetes:
60 pool:
61 service:
62 local:
63 enabled: False
64 service: libvirt
65 cluster: openstack-compute
66 namespace: default
67 role: ${linux:system:name}
68 type: LoadBalancer
69 kind: Deployment
70 apiVersion: extensions/v1beta1
71 replicas: 1
72 host_pid: True
73 nodeSelector:
74 - key: openstack
75 value: ${linux:system:name}
76 hostNetwork: True
77 container:
78 libvirt-compute:
79 privileged: True
80 image: ${_param:docker_repository}/libvirt-compute
81 tag: ${_param:openstack_container_tag}
Ales Komarek688a04c2016-07-15 15:12:30 +020082
83Master definition
84
marcoacdae7e2015-12-02 15:35:37 +010085.. code-block:: yaml
86
87 kubernetes:
Jakub Pavlik495d06f2016-06-17 11:33:05 +020088 master:
89 addons:
90 dns:
91 domain: cluster.local
92 enabled: true
93 replicas: 1
94 server: 10.254.0.10
Jakub Pavlik495d06f2016-06-17 11:33:05 +020095 admin:
96 password: password
97 username: admin
98 apiserver:
99 address: 10.0.175.100
Swann Croisetff97efc2017-02-23 13:32:33 +0100100 secure_port: 443
101 insecure_address: 127.0.0.1
102 insecure_port: 8080
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200103 ca: kubernetes
104 enabled: true
105 etcd:
106 host: 127.0.0.1
107 members:
108 - host: 10.0.175.100
109 name: node040
110 name: node040
111 token: ca939ec9c2a17b0786f6d411fe019e9b
112 kubelet:
113 allow_privileged: true
114 network:
115 engine: calico
116 hash: fb5e30ebe6154911a66ec3fb5f1195b2
117 private_ip_range: 10.150.0.0/16
118 version: v0.19.0
119 service_addresses: 10.254.0.0/16
120 storage:
121 engine: glusterfs
122 members:
123 - host: 10.0.175.101
124 port: 24007
125 - host: 10.0.175.102
126 port: 24007
127 - host: 10.0.175.103
128 port: 24007
129 port: 24007
130 token:
131 admin: DFvQ8GJ9JD4fKNfuyEddw3rjnFTkUKsv
132 controller_manager: EreGh6AnWf8DxH8cYavB2zS029PUi7vx
133 dns: RAFeVSE4UvsCz4gk3KYReuOI5jsZ1Xt3
134 kube_proxy: DFvQ8GelB7afH3wClC9romaMPhquyyEe
135 kubelet: 7bN5hJ9JD4fKjnFTkUKsvVNfuyEddw3r
136 logging: MJkXKdbgqRmTHSa2ykTaOaMykgO6KcEf
137 monitoring: hnsj0XqABgrSww7Nqo7UVTSZLJUt2XRd
138 scheduler: HY1UUxEPpmjW4a1dDLGIANYQp1nZkLDk
139 version: v1.2.4
140
marcoacdae7e2015-12-02 15:35:37 +0100141
142 kubernetes:
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200143 pool:
144 address: 0.0.0.0
145 allow_privileged: true
146 ca: kubernetes
147 cluster_dns: 10.254.0.10
148 cluster_domain: cluster.local
149 enabled: true
150 kubelet:
151 allow_privileged: true
152 config: /etc/kubernetes/manifests
153 frequency: 5s
154 master:
155 apiserver:
156 members:
157 - host: 10.0.175.100
158 etcd:
159 members:
160 - host: 10.0.175.100
161 host: 10.0.175.100
162 network:
163 engine: calico
164 hash: fb5e30ebe6154911a66ec3fb5f1195b2
165 version: v0.19.0
166 token:
167 kube_proxy: DFvQ8GelB7afH3wClC9romaMPhquyyEe
168 kubelet: 7bN5hJ9JD4fKjnFTkUKsvVNfuyEddw3r
169 version: v1.2.4
marcoacdae7e2015-12-02 15:35:37 +0100170
171
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200172
173Kubernetes with OpenContrail network plugin
174------------------------------------------------
marcoacdae7e2015-12-02 15:35:37 +0100175
176On Master:
177
178.. code-block:: yaml
179
180 kubernetes:
181 master:
182 network:
183 engine: opencontrail
184 host: 10.0.170.70
185 port: 8082
186 default_domain: default-domain
187 default_project: default-domain:default-project
188 public_network: default-domain:default-project:Public
189 public_ip_range: 185.22.97.128/26
190 private_ip_range: 10.150.0.0/16
191 service_cluster_ip_range: 10.254.0.0/16
192 network_label: name
193 service_label: uses
194 cluster_service: kube-system/default
195 network_manager:
196 image: pupapaik/opencontrail-kube-network-manager
197 tag: release-1.1-jpa-final-1
198
199On pools:
200
201.. code-block:: yaml
202
203 kubernetes:
204 pool:
205 network:
206 engine: opencontrail
207
Jakub Pavlik1cfc1fe2016-07-25 11:01:52 +0200208Kubernetes control plane running in systemd
209-------------------------------------------
210
211By 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.
212
213.. code-block:: yaml
214
215 kubernetes:
216 master:
217 container: false
218
219 kubernetes:
220 pool:
221 container: false
222
marco055ff852016-07-27 15:22:33 +0200223Because k8s services run under kube user without root privileges, there is need to change secure port for apiserver.
224
225.. code-block:: yaml
226
227 kubernetes:
228 master:
229 apiserver:
230 secure_port: 8081
231
marcoacdae7e2015-12-02 15:35:37 +0100232Kubernetes with Flannel
233-----------------------
234
235On Master:
236
237.. code-block:: yaml
238
239 kubernetes:
240 master:
241 network:
242 engine: flannel
Jakub Pavlik7e985322016-07-17 13:16:15 +0200243 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200244 etcd:
245 members:
246 - host: 10.0.175.101
247 port: 4001
248 - host: 10.0.175.102
249 port: 4001
250 - host: 10.0.175.103
251 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100252 common:
253 network:
254 engine: flannel
255
256On pools:
257
258.. code-block:: yaml
259
260 kubernetes:
261 pool:
262 network:
263 engine: flannel
marcoa05621f2016-07-14 10:35:24 +0200264 etcd:
265 members:
266 - host: 10.0.175.101
267 port: 4001
268 - host: 10.0.175.102
269 port: 4001
270 - host: 10.0.175.103
271 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100272 common:
273 network:
274 engine: flannel
275
276Kubernetes with Calico
277-----------------------
278
279On Master:
280
281.. code-block:: yaml
282
283 kubernetes:
284 master:
285 network:
286 engine: calico
Jakub Pavlik7e985322016-07-17 13:16:15 +0200287 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200288 etcd:
289 members:
290 - host: 10.0.175.101
291 port: 4001
292 - host: 10.0.175.102
293 port: 4001
294 - host: 10.0.175.103
295 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100296
297On pools:
298
299.. code-block:: yaml
300
301 kubernetes:
302 pool:
303 network:
304 engine: calico
marcoa05621f2016-07-14 10:35:24 +0200305 etcd:
306 members:
307 - host: 10.0.175.101
308 port: 4001
309 - host: 10.0.175.102
310 port: 4001
311 - host: 10.0.175.103
312 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100313
Jakub Pavlik7e985322016-07-17 13:16:15 +0200314Post deployment configuration
315
316.. code-block:: bash
Jakub Pavlik232833c2016-07-17 13:21:00 +0200317
Jakub Pavlik7e985322016-07-17 13:16:15 +0200318 # set ETCD
319 export ETCD_AUTHORITY=10.0.111.201:4001
320
321 # Set NAT for pods subnet
322 calicoctl pool add 192.168.0.0/16 --nat-outgoing
323
324 # Status commands
325 calicoctl status
326 calicoctl node show
327
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200328Kubernetes with GlusterFS for storage
329---------------------------------------------
330
331.. code-block:: yaml
332
333 kubernetes:
334 master
335 ...
336 storage:
337 engine: glusterfs
338 port: 24007
339 members:
340 - host: 10.0.175.101
341 port: 24007
342 - host: 10.0.175.102
343 port: 24007
344 - host: 10.0.175.103
345 port: 24007
346 ...
347
marco45fc1b72016-07-02 16:11:18 +0200348Kubernetes namespaces
349---------------------
350
351Create namespace:
352
353.. code-block:: yaml
354
355 kubernetes:
356 master
357 ...
358 namespace:
359 kube-system:
360 enabled: True
361 namespace2:
362 enabled: True
363 namespace3:
364 enabled: False
365 ...
366
367Kubernetes labels
368-----------------
369
Marek Celoud901020b2017-01-27 14:51:41 +0100370Label node:
marco45fc1b72016-07-02 16:11:18 +0200371
372.. code-block:: yaml
373
Marek Celoud901020b2017-01-27 14:51:41 +0100374 kubernetes:
375 master:
376 label:
377 label01:
378 value: value01
379 node: node01
380 enabled: true
381 key: key01
marco45fc1b72016-07-02 16:11:18 +0200382 ...
marco45fc1b72016-07-02 16:11:18 +0200383
marcof7efecb2016-07-16 16:13:37 +0200384Pull images from private registries
385-----------------------------------
386
387.. code-block:: yaml
388
389 kubernetes:
390 master
391 ...
392 registry:
393 secret:
394 registry01:
395 enabled: True
396 key: (get from `cat /root/.docker/config.json | base64`)
397 namespace: default
398 ...
399 control:
400 ...
401 service:
402 service01:
403 ...
404 image_pull_secretes: registry01
405 ...
406
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200407Kubernetes Service Definitions in pillars
408==========================================
409
410Following samples show how to generate kubernetes manifest as well and provide single tool for complete infrastructure management.
411
412Deployment manifest
413---------------------
marcoacdae7e2015-12-02 15:35:37 +0100414
415.. code-block:: yaml
416
417 salt:
418 control:
419 enabled: True
420 hostNetwork: True
421 service:
422 memcached:
423 privileged: True
424 service: memcached
425 role: server
426 type: LoadBalancer
427 replicas: 3
428 kind: Deployment
429 apiVersion: extensions/v1beta1
430 ports:
431 - port: 8774
432 name: nova-api
433 - port: 8775
434 name: nova-metadata
435 volume:
436 volume_name:
437 type: hostPath
438 mount: /certs
439 path: /etc/certs
440 container:
441 memcached:
442 image: memcached
443 tag:2
444 ports:
445 - port: 8774
446 name: nova-api
447 - port: 8775
448 name: nova-metadata
449 variables:
450 - name: HTTP_TLS_CERTIFICATE:
451 value: /certs/domain.crt
452 - name: HTTP_TLS_KEY
453 value: /certs/domain.key
454 volumes:
455 - name: /etc/certs
456 type: hostPath
457 mount: /certs
458 path: /etc/certs
459
marcobe30c8d2016-10-11 19:16:35 +0200460PetSet manifest
461---------------------
462
463.. code-block:: yaml
464
465 service:
466 memcached:
467 apiVersion: apps/v1alpha1
468 kind: PetSet
469 service_name: 'memcached'
470 container:
471 memcached:
472 ...
473
474
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200475Configmap
476---------
477
478You are able to create configmaps using support layer between formulas.
479It works simple, eg. in nova formula there's file ``meta/config.yml`` which
480defines config files used by that service and roles.
481
482Kubernetes formula is able to generate these files using custom pillar and
483grains structure. This way you are able to run docker images built by any way
484while still re-using your configuration management.
485
486Example pillar:
487
488.. code-block:: bash
489
490 kubernetes:
491 control:
Jakub Pavlika2779722016-11-25 15:35:26 +0100492 config_type: default|kubernetes # Output is yaml k8s or default single files
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200493 configmap:
494 nova-control:
495 grains:
496 # Alternate grains as OS running in container may differ from
497 # salt minion OS. Needed only if grains matters for config
498 # generation.
499 os_family: Debian
500 pillar:
501 # Generic pillar for nova controller
502 nova:
503 controller:
504 enabled: true
505 versionn: liberty
506 ...
507
508To tell which services supports config generation, you need to ensure pillar
509structure like this to determine support:
510
511.. code-block:: yaml
512
513 nova:
514 _support:
515 config:
516 enabled: true
517
marcod4d3dbd2016-09-27 11:36:40 +0200518initContainers
519--------------
520
521Example pillar:
522
523.. code-block:: bash
524
525 kubernetes:
526 control:
527 service:
528 memcached:
529 init_containers:
530 - name: test-mysql
531 image: busybox
532 command:
533 - sleep
534 - 3600
535 volumes:
536 - name: config
537 mount: /test
538 - name: test-memcached
539 image: busybox
540 command:
541 - sleep
542 - 3600
543 volumes:
544 - name: config
545 mount: /test
546
marcoee859d32016-11-07 11:04:57 +0100547Affinity
548--------
549
550podAffinity
551===========
552
553Example pillar:
554
555.. code-block:: bash
556
557 kubernetes:
558 control:
559 service:
560 memcached:
561 affinity:
562 pod_affinity:
563 name: podAffinity
564 expression:
565 label_selector:
566 name: labelSelector
567 selectors:
568 - key: app
569 value: memcached
570 topology_key: kubernetes.io/hostname
571
572podAntiAffinity
573===============
574
575Example pillar:
576
577.. code-block:: bash
578
579 kubernetes:
580 control:
581 service:
582 memcached:
583 affinity:
584 anti_affinity:
585 name: podAntiAffinity
586 expression:
587 label_selector:
588 name: labelSelector
589 selectors:
590 - key: app
591 value: opencontrail-control
592 topology_key: kubernetes.io/hostname
593
594nodeAffinity
595===============
596
597Example pillar:
598
599.. code-block:: bash
600
601 kubernetes:
602 control:
603 service:
604 memcached:
605 affinity:
606 node_affinity:
607 name: nodeAffinity
608 expression:
609 match_expressions:
610 name: matchExpressions
611 selectors:
612 - key: key
613 operator: In
614 values:
615 - value1
616 - value2
617
marcoacdae7e2015-12-02 15:35:37 +0100618Volumes
619-------
620
621hostPath
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200622==========
marcoacdae7e2015-12-02 15:35:37 +0100623
624.. code-block:: yaml
625
marcob469f882016-09-27 09:56:13 +0200626 service:
marcoacdae7e2015-12-02 15:35:37 +0100627 memcached:
marcob469f882016-09-27 09:56:13 +0200628 container:
629 memcached:
630 volumes:
631 - name: volume1
632 mountPath: /volume
633 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100634 ...
marcob469f882016-09-27 09:56:13 +0200635 volume:
636 volume1:
637 name: /etc/certs
638 type: hostPath
639 path: /etc/certs
marcoacdae7e2015-12-02 15:35:37 +0100640
641emptyDir
Ales Komarek688a04c2016-07-15 15:12:30 +0200642========
marcoacdae7e2015-12-02 15:35:37 +0100643
644.. code-block:: yaml
645
marcob469f882016-09-27 09:56:13 +0200646 service:
marcoacdae7e2015-12-02 15:35:37 +0100647 memcached:
marcob469f882016-09-27 09:56:13 +0200648 container:
649 memcached:
650 volumes:
651 - name: volume1
652 mountPath: /volume
653 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100654 ...
marcob469f882016-09-27 09:56:13 +0200655 volume:
656 volume1:
657 name: /etc/certs
658 type: emptyDir
659
660configMap
661=========
662
663.. code-block:: yaml
664
665 service:
666 memcached:
667 container:
668 memcached:
669 volumes:
670 - name: volume1
671 mountPath: /volume
672 readOnly: True
673 ...
674 volume:
675 volume1:
676 type: config_map
677 item:
678 configMap1:
679 key: config.conf
680 path: config.conf
681 configMap2:
682 key: policy.json
683 path: policy.json
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200684
marco0eda4fb2016-10-10 19:08:27 +0200685To mount single configuration file instead of whole directory:
686
687.. code-block:: yaml
688
689 service:
690 memcached:
691 container:
692 memcached:
693 volumes:
694 - name: volume1
695 mountPath: /volume/config.conf
696 sub_path: config.conf
697
marcofcc20d02016-10-10 09:56:12 +0200698Generating Jobs
699===============
700
701Example pillar:
702
703.. code-block:: yaml
704
705 kubernetes:
706 control:
707 job:
708 sleep:
709 job: sleep
710 restart_policy: Never
711 container:
712 sleep:
713 image: busybox
714 tag: latest
715 command:
716 - sleep
717 - "3600"
718
719Volumes and Variables can be used as the same way as during Deployment generation.
720
721Custom params:
722
723.. code-block:: yaml
724
725 kubernetes:
726 control:
727 job:
728 host_network: True
729 host_pid: True
730 container:
731 sleep:
732 privileged: True
733 node_selector:
734 key: node
735 value: one
736 image_pull_secretes: password
737
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200738Documentation and Bugs
Filip Pytloun06a55402016-08-12 14:53:30 +0200739======================
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200740
741To learn how to deploy OpenStack Salt, consult the documentation available
742online at:
743
744 https://wiki.openstack.org/wiki/OpenStackSalt
745
746In the unfortunate event that bugs are discovered, they should be reported to
747the appropriate bug tracker. If you obtained the software from a 3rd party
748operating system vendor, it is often wise to use their own bug tracker for
749reporting problems. In all other cases use the master OpenStack bug tracker,
750available at:
751
752 http://bugs.launchpad.net/openstack-salt
753
754Developers wishing to work on the OpenStack Salt project should always base
755their work on the latest formulas code, available from the master GIT
756repository at:
757
758 https://git.openstack.org/cgit/openstack/salt-formula-kubernetes
759
760Developers should also join the discussion on the IRC list, at:
761
762 https://wiki.openstack.org/wiki/Meetings/openstack-salt
Filip Pytloun06a55402016-08-12 14:53:30 +0200763
764Copyright and authors
765=====================
766
767(c) 2016 tcp cloud a.s.
768(c) 2016 OpenStack Foundation
Filip Pytlound06f6272017-02-02 13:02:03 +0100769
770Documentation and Bugs
771======================
772
773To learn how to install and update salt-formulas, consult the documentation
774available online at:
775
776 http://salt-formulas.readthedocs.io/
777
778In the unfortunate event that bugs are discovered, they should be reported to
779the appropriate issue tracker. Use Github issue tracker for specific salt
780formula:
781
782 https://github.com/salt-formulas/salt-formula-kubernetes/issues
783
784For feature requests, bug reports or blueprints affecting entire ecosystem,
785use Launchpad salt-formulas project:
786
787 https://launchpad.net/salt-formulas
788
789You can also join salt-formulas-users team and subscribe to mailing list:
790
791 https://launchpad.net/~salt-formulas-users
792
793Developers wishing to work on the salt-formulas projects should always base
794their work on master branch and submit pull request against specific formula.
795
796 https://github.com/salt-formulas/salt-formula-kubernetes
797
798Any questions or feedback is always welcome so feel free to join our IRC
799channel:
800
801 #salt-formulas @ irc.freenode.net