blob: ddf734c2b8b54c7f2fe726b13b7ba3720db306f4 [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á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
Tomáš Kukrál34c59362017-03-01 14:00:37 +0100314Running with secured etcd:
315
316.. code-block:: yaml
317
318 kubernetes:
319 pool:
320 network:
321 engine: calico
322 etcd:
323 ssl:
324 enabled: true
325 master:
326 network:
327 engine: calico
328 etcd:
329 ssl:
330 enabled: true
331
Jakub Pavlik7e985322016-07-17 13:16:15 +0200332Post deployment configuration
333
334.. code-block:: bash
Jakub Pavlik232833c2016-07-17 13:21:00 +0200335
Jakub Pavlik7e985322016-07-17 13:16:15 +0200336 # set ETCD
337 export ETCD_AUTHORITY=10.0.111.201:4001
338
339 # Set NAT for pods subnet
340 calicoctl pool add 192.168.0.0/16 --nat-outgoing
341
342 # Status commands
343 calicoctl status
344 calicoctl node show
345
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200346Kubernetes with GlusterFS for storage
347---------------------------------------------
348
349.. code-block:: yaml
350
351 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100352 master:
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200353 ...
354 storage:
355 engine: glusterfs
356 port: 24007
357 members:
358 - host: 10.0.175.101
359 port: 24007
360 - host: 10.0.175.102
361 port: 24007
362 - host: 10.0.175.103
363 port: 24007
364 ...
365
marco45fc1b72016-07-02 16:11:18 +0200366Kubernetes namespaces
367---------------------
368
369Create namespace:
370
371.. code-block:: yaml
372
373 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100374 master:
marco45fc1b72016-07-02 16:11:18 +0200375 ...
376 namespace:
377 kube-system:
378 enabled: True
379 namespace2:
380 enabled: True
381 namespace3:
382 enabled: False
383 ...
384
385Kubernetes labels
386-----------------
387
Marek Celoud901020b2017-01-27 14:51:41 +0100388Label node:
marco45fc1b72016-07-02 16:11:18 +0200389
390.. code-block:: yaml
391
Marek Celoud901020b2017-01-27 14:51:41 +0100392 kubernetes:
393 master:
394 label:
395 label01:
396 value: value01
397 node: node01
398 enabled: true
399 key: key01
marco45fc1b72016-07-02 16:11:18 +0200400 ...
marco45fc1b72016-07-02 16:11:18 +0200401
marcof7efecb2016-07-16 16:13:37 +0200402Pull images from private registries
403-----------------------------------
404
405.. code-block:: yaml
406
407 kubernetes:
Tomáš Kukrál4f0dae32017-03-21 19:04:19 +0100408 master:
marcof7efecb2016-07-16 16:13:37 +0200409 ...
410 registry:
411 secret:
412 registry01:
413 enabled: True
414 key: (get from `cat /root/.docker/config.json | base64`)
415 namespace: default
416 ...
417 control:
418 ...
419 service:
420 service01:
421 ...
422 image_pull_secretes: registry01
423 ...
424
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200425Kubernetes Service Definitions in pillars
426==========================================
427
428Following samples show how to generate kubernetes manifest as well and provide single tool for complete infrastructure management.
429
430Deployment manifest
431---------------------
marcoacdae7e2015-12-02 15:35:37 +0100432
433.. code-block:: yaml
434
435 salt:
436 control:
437 enabled: True
438 hostNetwork: True
439 service:
440 memcached:
441 privileged: True
442 service: memcached
443 role: server
444 type: LoadBalancer
445 replicas: 3
446 kind: Deployment
447 apiVersion: extensions/v1beta1
448 ports:
449 - port: 8774
450 name: nova-api
451 - port: 8775
452 name: nova-metadata
453 volume:
454 volume_name:
455 type: hostPath
456 mount: /certs
457 path: /etc/certs
458 container:
459 memcached:
460 image: memcached
461 tag:2
462 ports:
463 - port: 8774
464 name: nova-api
465 - port: 8775
466 name: nova-metadata
467 variables:
468 - name: HTTP_TLS_CERTIFICATE:
469 value: /certs/domain.crt
470 - name: HTTP_TLS_KEY
471 value: /certs/domain.key
472 volumes:
473 - name: /etc/certs
474 type: hostPath
475 mount: /certs
476 path: /etc/certs
477
marcobe30c8d2016-10-11 19:16:35 +0200478PetSet manifest
479---------------------
480
481.. code-block:: yaml
482
483 service:
484 memcached:
485 apiVersion: apps/v1alpha1
486 kind: PetSet
487 service_name: 'memcached'
488 container:
489 memcached:
490 ...
491
492
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200493Configmap
494---------
495
496You are able to create configmaps using support layer between formulas.
497It works simple, eg. in nova formula there's file ``meta/config.yml`` which
498defines config files used by that service and roles.
499
500Kubernetes formula is able to generate these files using custom pillar and
501grains structure. This way you are able to run docker images built by any way
502while still re-using your configuration management.
503
504Example pillar:
505
506.. code-block:: bash
507
508 kubernetes:
509 control:
Jakub Pavlika2779722016-11-25 15:35:26 +0100510 config_type: default|kubernetes # Output is yaml k8s or default single files
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200511 configmap:
512 nova-control:
513 grains:
514 # Alternate grains as OS running in container may differ from
515 # salt minion OS. Needed only if grains matters for config
516 # generation.
517 os_family: Debian
518 pillar:
519 # Generic pillar for nova controller
520 nova:
521 controller:
522 enabled: true
523 versionn: liberty
524 ...
525
526To tell which services supports config generation, you need to ensure pillar
527structure like this to determine support:
528
529.. code-block:: yaml
530
531 nova:
532 _support:
533 config:
534 enabled: true
535
marcod4d3dbd2016-09-27 11:36:40 +0200536initContainers
537--------------
538
539Example pillar:
540
541.. code-block:: bash
542
543 kubernetes:
544 control:
545 service:
546 memcached:
547 init_containers:
548 - name: test-mysql
549 image: busybox
550 command:
551 - sleep
552 - 3600
553 volumes:
554 - name: config
555 mount: /test
556 - name: test-memcached
557 image: busybox
558 command:
559 - sleep
560 - 3600
561 volumes:
562 - name: config
563 mount: /test
564
marcoee859d32016-11-07 11:04:57 +0100565Affinity
566--------
567
568podAffinity
569===========
570
571Example pillar:
572
573.. code-block:: bash
574
575 kubernetes:
576 control:
577 service:
578 memcached:
579 affinity:
580 pod_affinity:
581 name: podAffinity
582 expression:
583 label_selector:
584 name: labelSelector
585 selectors:
586 - key: app
587 value: memcached
588 topology_key: kubernetes.io/hostname
589
590podAntiAffinity
591===============
592
593Example pillar:
594
595.. code-block:: bash
596
597 kubernetes:
598 control:
599 service:
600 memcached:
601 affinity:
602 anti_affinity:
603 name: podAntiAffinity
604 expression:
605 label_selector:
606 name: labelSelector
607 selectors:
608 - key: app
609 value: opencontrail-control
610 topology_key: kubernetes.io/hostname
611
612nodeAffinity
613===============
614
615Example pillar:
616
617.. code-block:: bash
618
619 kubernetes:
620 control:
621 service:
622 memcached:
623 affinity:
624 node_affinity:
625 name: nodeAffinity
626 expression:
627 match_expressions:
628 name: matchExpressions
629 selectors:
630 - key: key
631 operator: In
632 values:
633 - value1
634 - value2
635
marcoacdae7e2015-12-02 15:35:37 +0100636Volumes
637-------
638
639hostPath
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200640==========
marcoacdae7e2015-12-02 15:35:37 +0100641
642.. code-block:: yaml
643
marcob469f882016-09-27 09:56:13 +0200644 service:
marcoacdae7e2015-12-02 15:35:37 +0100645 memcached:
marcob469f882016-09-27 09:56:13 +0200646 container:
647 memcached:
648 volumes:
649 - name: volume1
650 mountPath: /volume
651 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100652 ...
marcob469f882016-09-27 09:56:13 +0200653 volume:
654 volume1:
655 name: /etc/certs
656 type: hostPath
657 path: /etc/certs
marcoacdae7e2015-12-02 15:35:37 +0100658
659emptyDir
Ales Komarek688a04c2016-07-15 15:12:30 +0200660========
marcoacdae7e2015-12-02 15:35:37 +0100661
662.. code-block:: yaml
663
marcob469f882016-09-27 09:56:13 +0200664 service:
marcoacdae7e2015-12-02 15:35:37 +0100665 memcached:
marcob469f882016-09-27 09:56:13 +0200666 container:
667 memcached:
668 volumes:
669 - name: volume1
670 mountPath: /volume
671 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100672 ...
marcob469f882016-09-27 09:56:13 +0200673 volume:
674 volume1:
675 name: /etc/certs
676 type: emptyDir
677
678configMap
679=========
680
681.. code-block:: yaml
682
683 service:
684 memcached:
685 container:
686 memcached:
687 volumes:
688 - name: volume1
689 mountPath: /volume
690 readOnly: True
691 ...
692 volume:
693 volume1:
694 type: config_map
695 item:
696 configMap1:
697 key: config.conf
698 path: config.conf
699 configMap2:
700 key: policy.json
701 path: policy.json
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200702
marco0eda4fb2016-10-10 19:08:27 +0200703To mount single configuration file instead of whole directory:
704
705.. code-block:: yaml
706
707 service:
708 memcached:
709 container:
710 memcached:
711 volumes:
712 - name: volume1
713 mountPath: /volume/config.conf
714 sub_path: config.conf
715
marcofcc20d02016-10-10 09:56:12 +0200716Generating Jobs
717===============
718
719Example pillar:
720
721.. code-block:: yaml
722
723 kubernetes:
724 control:
725 job:
726 sleep:
727 job: sleep
728 restart_policy: Never
729 container:
730 sleep:
731 image: busybox
732 tag: latest
733 command:
734 - sleep
735 - "3600"
736
737Volumes and Variables can be used as the same way as during Deployment generation.
738
739Custom params:
740
741.. code-block:: yaml
742
743 kubernetes:
744 control:
745 job:
746 host_network: True
747 host_pid: True
748 container:
749 sleep:
750 privileged: True
751 node_selector:
752 key: node
753 value: one
754 image_pull_secretes: password
755
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200756Documentation and Bugs
Filip Pytloun06a55402016-08-12 14:53:30 +0200757======================
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200758
759To learn how to deploy OpenStack Salt, consult the documentation available
760online at:
761
762 https://wiki.openstack.org/wiki/OpenStackSalt
763
764In the unfortunate event that bugs are discovered, they should be reported to
765the appropriate bug tracker. If you obtained the software from a 3rd party
766operating system vendor, it is often wise to use their own bug tracker for
767reporting problems. In all other cases use the master OpenStack bug tracker,
768available at:
769
770 http://bugs.launchpad.net/openstack-salt
771
772Developers wishing to work on the OpenStack Salt project should always base
773their work on the latest formulas code, available from the master GIT
774repository at:
775
776 https://git.openstack.org/cgit/openstack/salt-formula-kubernetes
777
778Developers should also join the discussion on the IRC list, at:
779
780 https://wiki.openstack.org/wiki/Meetings/openstack-salt
Filip Pytloun06a55402016-08-12 14:53:30 +0200781
782Copyright and authors
783=====================
784
785(c) 2016 tcp cloud a.s.
786(c) 2016 OpenStack Foundation
Filip Pytlound06f6272017-02-02 13:02:03 +0100787
788Documentation and Bugs
789======================
790
791To learn how to install and update salt-formulas, consult the documentation
792available online at:
793
794 http://salt-formulas.readthedocs.io/
795
796In the unfortunate event that bugs are discovered, they should be reported to
797the appropriate issue tracker. Use Github issue tracker for specific salt
798formula:
799
800 https://github.com/salt-formulas/salt-formula-kubernetes/issues
801
802For feature requests, bug reports or blueprints affecting entire ecosystem,
803use Launchpad salt-formulas project:
804
805 https://launchpad.net/salt-formulas
806
807You can also join salt-formulas-users team and subscribe to mailing list:
808
809 https://launchpad.net/~salt-formulas-users
810
811Developers wishing to work on the salt-formulas projects should always base
812their work on master branch and submit pull request against specific formula.
813
814 https://github.com/salt-formulas/salt-formula-kubernetes
815
816Any questions or feedback is always welcome so feel free to join our IRC
817channel:
818
819 #salt-formulas @ irc.freenode.net