blob: f2aa3502177636cf5d1fc156fe0b729588776f82 [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
35
Ales Komarek688a04c2016-07-15 15:12:30 +020036Containers on pool definitions in pool.service.local
37
Jakub Pavlik7e985322016-07-17 13:16:15 +020038.. code-block:: yaml
39
40 parameters:
41 kubernetes:
42 pool:
43 service:
44 local:
45 enabled: False
46 service: libvirt
47 cluster: openstack-compute
48 namespace: default
49 role: ${linux:system:name}
50 type: LoadBalancer
51 kind: Deployment
52 apiVersion: extensions/v1beta1
53 replicas: 1
54 host_pid: True
55 nodeSelector:
56 - key: openstack
57 value: ${linux:system:name}
58 hostNetwork: True
59 container:
60 libvirt-compute:
61 privileged: True
62 image: ${_param:docker_repository}/libvirt-compute
63 tag: ${_param:openstack_container_tag}
Ales Komarek688a04c2016-07-15 15:12:30 +020064
65Master definition
66
marcoacdae7e2015-12-02 15:35:37 +010067.. code-block:: yaml
68
69 kubernetes:
Jakub Pavlik495d06f2016-06-17 11:33:05 +020070 master:
71 addons:
72 dns:
73 domain: cluster.local
74 enabled: true
75 replicas: 1
76 server: 10.254.0.10
Jakub Pavlik495d06f2016-06-17 11:33:05 +020077 admin:
78 password: password
79 username: admin
80 apiserver:
81 address: 10.0.175.100
82 port: 8080
83 ca: kubernetes
84 enabled: true
85 etcd:
86 host: 127.0.0.1
87 members:
88 - host: 10.0.175.100
89 name: node040
90 name: node040
91 token: ca939ec9c2a17b0786f6d411fe019e9b
92 kubelet:
93 allow_privileged: true
94 network:
95 engine: calico
96 hash: fb5e30ebe6154911a66ec3fb5f1195b2
97 private_ip_range: 10.150.0.0/16
98 version: v0.19.0
99 service_addresses: 10.254.0.0/16
100 storage:
101 engine: glusterfs
102 members:
103 - host: 10.0.175.101
104 port: 24007
105 - host: 10.0.175.102
106 port: 24007
107 - host: 10.0.175.103
108 port: 24007
109 port: 24007
110 token:
111 admin: DFvQ8GJ9JD4fKNfuyEddw3rjnFTkUKsv
112 controller_manager: EreGh6AnWf8DxH8cYavB2zS029PUi7vx
113 dns: RAFeVSE4UvsCz4gk3KYReuOI5jsZ1Xt3
114 kube_proxy: DFvQ8GelB7afH3wClC9romaMPhquyyEe
115 kubelet: 7bN5hJ9JD4fKjnFTkUKsvVNfuyEddw3r
116 logging: MJkXKdbgqRmTHSa2ykTaOaMykgO6KcEf
117 monitoring: hnsj0XqABgrSww7Nqo7UVTSZLJUt2XRd
118 scheduler: HY1UUxEPpmjW4a1dDLGIANYQp1nZkLDk
119 version: v1.2.4
120
marcoacdae7e2015-12-02 15:35:37 +0100121
122 kubernetes:
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200123 pool:
124 address: 0.0.0.0
125 allow_privileged: true
126 ca: kubernetes
127 cluster_dns: 10.254.0.10
128 cluster_domain: cluster.local
129 enabled: true
130 kubelet:
131 allow_privileged: true
132 config: /etc/kubernetes/manifests
133 frequency: 5s
134 master:
135 apiserver:
136 members:
137 - host: 10.0.175.100
138 etcd:
139 members:
140 - host: 10.0.175.100
141 host: 10.0.175.100
142 network:
143 engine: calico
144 hash: fb5e30ebe6154911a66ec3fb5f1195b2
145 version: v0.19.0
146 token:
147 kube_proxy: DFvQ8GelB7afH3wClC9romaMPhquyyEe
148 kubelet: 7bN5hJ9JD4fKjnFTkUKsvVNfuyEddw3r
149 version: v1.2.4
marcoacdae7e2015-12-02 15:35:37 +0100150
151
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200152
153Kubernetes with OpenContrail network plugin
154------------------------------------------------
marcoacdae7e2015-12-02 15:35:37 +0100155
156On Master:
157
158.. code-block:: yaml
159
160 kubernetes:
161 master:
162 network:
163 engine: opencontrail
164 host: 10.0.170.70
165 port: 8082
166 default_domain: default-domain
167 default_project: default-domain:default-project
168 public_network: default-domain:default-project:Public
169 public_ip_range: 185.22.97.128/26
170 private_ip_range: 10.150.0.0/16
171 service_cluster_ip_range: 10.254.0.0/16
172 network_label: name
173 service_label: uses
174 cluster_service: kube-system/default
175 network_manager:
176 image: pupapaik/opencontrail-kube-network-manager
177 tag: release-1.1-jpa-final-1
178
179On pools:
180
181.. code-block:: yaml
182
183 kubernetes:
184 pool:
185 network:
186 engine: opencontrail
187
Jakub Pavlik1cfc1fe2016-07-25 11:01:52 +0200188Kubernetes control plane running in systemd
189-------------------------------------------
190
191By 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.
192
193.. code-block:: yaml
194
195 kubernetes:
196 master:
197 container: false
198
199 kubernetes:
200 pool:
201 container: false
202
marco055ff852016-07-27 15:22:33 +0200203Because k8s services run under kube user without root privileges, there is need to change secure port for apiserver.
204
205.. code-block:: yaml
206
207 kubernetes:
208 master:
209 apiserver:
210 secure_port: 8081
211
marcoacdae7e2015-12-02 15:35:37 +0100212Kubernetes with Flannel
213-----------------------
214
215On Master:
216
217.. code-block:: yaml
218
219 kubernetes:
220 master:
221 network:
222 engine: flannel
Jakub Pavlik7e985322016-07-17 13:16:15 +0200223 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200224 etcd:
225 members:
226 - host: 10.0.175.101
227 port: 4001
228 - host: 10.0.175.102
229 port: 4001
230 - host: 10.0.175.103
231 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100232 common:
233 network:
234 engine: flannel
235
236On pools:
237
238.. code-block:: yaml
239
240 kubernetes:
241 pool:
242 network:
243 engine: flannel
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
256Kubernetes with Calico
257-----------------------
258
259On Master:
260
261.. code-block:: yaml
262
263 kubernetes:
264 master:
265 network:
266 engine: calico
Jakub Pavlik7e985322016-07-17 13:16:15 +0200267 # If you don't register master as node:
marcoa05621f2016-07-14 10:35:24 +0200268 etcd:
269 members:
270 - host: 10.0.175.101
271 port: 4001
272 - host: 10.0.175.102
273 port: 4001
274 - host: 10.0.175.103
275 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100276
277On pools:
278
279.. code-block:: yaml
280
281 kubernetes:
282 pool:
283 network:
284 engine: calico
marcoa05621f2016-07-14 10:35:24 +0200285 etcd:
286 members:
287 - host: 10.0.175.101
288 port: 4001
289 - host: 10.0.175.102
290 port: 4001
291 - host: 10.0.175.103
292 port: 4001
marcoacdae7e2015-12-02 15:35:37 +0100293
Jakub Pavlik7e985322016-07-17 13:16:15 +0200294Post deployment configuration
295
296.. code-block:: bash
Jakub Pavlik232833c2016-07-17 13:21:00 +0200297
Jakub Pavlik7e985322016-07-17 13:16:15 +0200298 # set ETCD
299 export ETCD_AUTHORITY=10.0.111.201:4001
300
301 # Set NAT for pods subnet
302 calicoctl pool add 192.168.0.0/16 --nat-outgoing
303
304 # Status commands
305 calicoctl status
306 calicoctl node show
307
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200308Kubernetes with GlusterFS for storage
309---------------------------------------------
310
311.. code-block:: yaml
312
313 kubernetes:
314 master
315 ...
316 storage:
317 engine: glusterfs
318 port: 24007
319 members:
320 - host: 10.0.175.101
321 port: 24007
322 - host: 10.0.175.102
323 port: 24007
324 - host: 10.0.175.103
325 port: 24007
326 ...
327
marco45fc1b72016-07-02 16:11:18 +0200328Kubernetes namespaces
329---------------------
330
331Create namespace:
332
333.. code-block:: yaml
334
335 kubernetes:
336 master
337 ...
338 namespace:
339 kube-system:
340 enabled: True
341 namespace2:
342 enabled: True
343 namespace3:
344 enabled: False
345 ...
346
347Kubernetes labels
348-----------------
349
Marek Celoud901020b2017-01-27 14:51:41 +0100350Label node:
marco45fc1b72016-07-02 16:11:18 +0200351
352.. code-block:: yaml
353
Marek Celoud901020b2017-01-27 14:51:41 +0100354 kubernetes:
355 master:
356 label:
357 label01:
358 value: value01
359 node: node01
360 enabled: true
361 key: key01
marco45fc1b72016-07-02 16:11:18 +0200362 ...
marco45fc1b72016-07-02 16:11:18 +0200363
marcof7efecb2016-07-16 16:13:37 +0200364Pull images from private registries
365-----------------------------------
366
367.. code-block:: yaml
368
369 kubernetes:
370 master
371 ...
372 registry:
373 secret:
374 registry01:
375 enabled: True
376 key: (get from `cat /root/.docker/config.json | base64`)
377 namespace: default
378 ...
379 control:
380 ...
381 service:
382 service01:
383 ...
384 image_pull_secretes: registry01
385 ...
386
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200387Kubernetes Service Definitions in pillars
388==========================================
389
390Following samples show how to generate kubernetes manifest as well and provide single tool for complete infrastructure management.
391
392Deployment manifest
393---------------------
marcoacdae7e2015-12-02 15:35:37 +0100394
395.. code-block:: yaml
396
397 salt:
398 control:
399 enabled: True
400 hostNetwork: True
401 service:
402 memcached:
403 privileged: True
404 service: memcached
405 role: server
406 type: LoadBalancer
407 replicas: 3
408 kind: Deployment
409 apiVersion: extensions/v1beta1
410 ports:
411 - port: 8774
412 name: nova-api
413 - port: 8775
414 name: nova-metadata
415 volume:
416 volume_name:
417 type: hostPath
418 mount: /certs
419 path: /etc/certs
420 container:
421 memcached:
422 image: memcached
423 tag:2
424 ports:
425 - port: 8774
426 name: nova-api
427 - port: 8775
428 name: nova-metadata
429 variables:
430 - name: HTTP_TLS_CERTIFICATE:
431 value: /certs/domain.crt
432 - name: HTTP_TLS_KEY
433 value: /certs/domain.key
434 volumes:
435 - name: /etc/certs
436 type: hostPath
437 mount: /certs
438 path: /etc/certs
439
marcobe30c8d2016-10-11 19:16:35 +0200440PetSet manifest
441---------------------
442
443.. code-block:: yaml
444
445 service:
446 memcached:
447 apiVersion: apps/v1alpha1
448 kind: PetSet
449 service_name: 'memcached'
450 container:
451 memcached:
452 ...
453
454
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200455Configmap
456---------
457
458You are able to create configmaps using support layer between formulas.
459It works simple, eg. in nova formula there's file ``meta/config.yml`` which
460defines config files used by that service and roles.
461
462Kubernetes formula is able to generate these files using custom pillar and
463grains structure. This way you are able to run docker images built by any way
464while still re-using your configuration management.
465
466Example pillar:
467
468.. code-block:: bash
469
470 kubernetes:
471 control:
Jakub Pavlika2779722016-11-25 15:35:26 +0100472 config_type: default|kubernetes # Output is yaml k8s or default single files
Filip Pytloun9a4a40f2016-09-22 16:28:19 +0200473 configmap:
474 nova-control:
475 grains:
476 # Alternate grains as OS running in container may differ from
477 # salt minion OS. Needed only if grains matters for config
478 # generation.
479 os_family: Debian
480 pillar:
481 # Generic pillar for nova controller
482 nova:
483 controller:
484 enabled: true
485 versionn: liberty
486 ...
487
488To tell which services supports config generation, you need to ensure pillar
489structure like this to determine support:
490
491.. code-block:: yaml
492
493 nova:
494 _support:
495 config:
496 enabled: true
497
marcod4d3dbd2016-09-27 11:36:40 +0200498initContainers
499--------------
500
501Example pillar:
502
503.. code-block:: bash
504
505 kubernetes:
506 control:
507 service:
508 memcached:
509 init_containers:
510 - name: test-mysql
511 image: busybox
512 command:
513 - sleep
514 - 3600
515 volumes:
516 - name: config
517 mount: /test
518 - name: test-memcached
519 image: busybox
520 command:
521 - sleep
522 - 3600
523 volumes:
524 - name: config
525 mount: /test
526
marcoee859d32016-11-07 11:04:57 +0100527Affinity
528--------
529
530podAffinity
531===========
532
533Example pillar:
534
535.. code-block:: bash
536
537 kubernetes:
538 control:
539 service:
540 memcached:
541 affinity:
542 pod_affinity:
543 name: podAffinity
544 expression:
545 label_selector:
546 name: labelSelector
547 selectors:
548 - key: app
549 value: memcached
550 topology_key: kubernetes.io/hostname
551
552podAntiAffinity
553===============
554
555Example pillar:
556
557.. code-block:: bash
558
559 kubernetes:
560 control:
561 service:
562 memcached:
563 affinity:
564 anti_affinity:
565 name: podAntiAffinity
566 expression:
567 label_selector:
568 name: labelSelector
569 selectors:
570 - key: app
571 value: opencontrail-control
572 topology_key: kubernetes.io/hostname
573
574nodeAffinity
575===============
576
577Example pillar:
578
579.. code-block:: bash
580
581 kubernetes:
582 control:
583 service:
584 memcached:
585 affinity:
586 node_affinity:
587 name: nodeAffinity
588 expression:
589 match_expressions:
590 name: matchExpressions
591 selectors:
592 - key: key
593 operator: In
594 values:
595 - value1
596 - value2
597
marcoacdae7e2015-12-02 15:35:37 +0100598Volumes
599-------
600
601hostPath
Jakub Pavlik495d06f2016-06-17 11:33:05 +0200602==========
marcoacdae7e2015-12-02 15:35:37 +0100603
604.. code-block:: yaml
605
marcob469f882016-09-27 09:56:13 +0200606 service:
marcoacdae7e2015-12-02 15:35:37 +0100607 memcached:
marcob469f882016-09-27 09:56:13 +0200608 container:
609 memcached:
610 volumes:
611 - name: volume1
612 mountPath: /volume
613 readOnly: True
marcoacdae7e2015-12-02 15:35:37 +0100614 ...
marcob469f882016-09-27 09:56:13 +0200615 volume:
616 volume1:
617 name: /etc/certs
618 type: hostPath
619 path: /etc/certs
marcoacdae7e2015-12-02 15:35:37 +0100620
621emptyDir
Ales Komarek688a04c2016-07-15 15:12:30 +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: emptyDir
639
640configMap
641=========
642
643.. code-block:: yaml
644
645 service:
646 memcached:
647 container:
648 memcached:
649 volumes:
650 - name: volume1
651 mountPath: /volume
652 readOnly: True
653 ...
654 volume:
655 volume1:
656 type: config_map
657 item:
658 configMap1:
659 key: config.conf
660 path: config.conf
661 configMap2:
662 key: policy.json
663 path: policy.json
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200664
marco0eda4fb2016-10-10 19:08:27 +0200665To mount single configuration file instead of whole directory:
666
667.. code-block:: yaml
668
669 service:
670 memcached:
671 container:
672 memcached:
673 volumes:
674 - name: volume1
675 mountPath: /volume/config.conf
676 sub_path: config.conf
677
marcofcc20d02016-10-10 09:56:12 +0200678Generating Jobs
679===============
680
681Example pillar:
682
683.. code-block:: yaml
684
685 kubernetes:
686 control:
687 job:
688 sleep:
689 job: sleep
690 restart_policy: Never
691 container:
692 sleep:
693 image: busybox
694 tag: latest
695 command:
696 - sleep
697 - "3600"
698
699Volumes and Variables can be used as the same way as during Deployment generation.
700
701Custom params:
702
703.. code-block:: yaml
704
705 kubernetes:
706 control:
707 job:
708 host_network: True
709 host_pid: True
710 container:
711 sleep:
712 privileged: True
713 node_selector:
714 key: node
715 value: one
716 image_pull_secretes: password
717
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200718Documentation and Bugs
Filip Pytloun06a55402016-08-12 14:53:30 +0200719======================
Jakub Pavlik27ad3a62016-08-05 11:39:45 +0200720
721To learn how to deploy OpenStack Salt, consult the documentation available
722online at:
723
724 https://wiki.openstack.org/wiki/OpenStackSalt
725
726In the unfortunate event that bugs are discovered, they should be reported to
727the appropriate bug tracker. If you obtained the software from a 3rd party
728operating system vendor, it is often wise to use their own bug tracker for
729reporting problems. In all other cases use the master OpenStack bug tracker,
730available at:
731
732 http://bugs.launchpad.net/openstack-salt
733
734Developers wishing to work on the OpenStack Salt project should always base
735their work on the latest formulas code, available from the master GIT
736repository at:
737
738 https://git.openstack.org/cgit/openstack/salt-formula-kubernetes
739
740Developers should also join the discussion on the IRC list, at:
741
742 https://wiki.openstack.org/wiki/Meetings/openstack-salt
Filip Pytloun06a55402016-08-12 14:53:30 +0200743
744Copyright and authors
745=====================
746
747(c) 2016 tcp cloud a.s.
748(c) 2016 OpenStack Foundation