Skip to content

Commit 85b61f4

Browse files
authored
Merge pull request #270 from Yolean/storagclass-kustomize
Use standard storage class by default, demonstrate kustomization per hosting provider
2 parents d5fc680 + 61555c3 commit 85b61f4

32 files changed

+219
-85
lines changed

README.md

+23-15
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ To quote [@arthurk](https://github.com/Yolean/kubernetes-kafka/issues/82#issueco
1212
## Getting started
1313

1414
We suggest you `apply -f` manifests in the following order:
15-
* Your choice of storage classes from [./configure](./configure/)
1615
* [namespace](./00-namespace.yml)
1716
* [./rbac-namespace-default](./rbac-namespace-default/)
1817
* [./zookeeper](./zookeeper/)
1918
* [./kafka](./kafka/)
2019

2120
That'll give you client "bootstrap" `bootstrap.kafka.svc.cluster.local:9092`.
2221

22+
With the introduction of [-k](#kustomize) support, apply `-f` will report `error: unable to decode "zookeeper/kustomization.yaml": Object 'Kind' is missing in ...`. With kubectl v1.14+ you can avoid that using: `kubectl apply -k variants/scale-3-5/`.
23+
2324
## Fork
2425

2526
Our only dependency is `kubectl`. Not because we dislike Helm or Operators, but because we think plain manifests make it easier to collaborate.
@@ -30,21 +31,35 @@ If you begin to rely on this kafka setup we recommend you fork, for example to e
3031
With the introduction of [app customization](https://kubectl.docs.kubernetes.io/pages/app_customization/introduction.html) in `kubectl` 1.14 there's an alternative to forks. We as a community can maintain a set of overlays.
3132

3233
See the [variants](./variants) folder for different overlays. For example to scale to 1 kafka broker try `kubectl apply -k variants/scale-1/`.
34+
Variants also include examples of how to configure volumes for GKE, AWS and AKS with different storage classes.
35+
36+
### Quickstart
3337

34-
Currently `apply -k` replaces `apply -f ./zookeeper; apply -f ./kafka`.
35-
The original commands now result in `error: unable to decode "zookeeper/kustomization.yaml": Object 'Kind' is missing in ...`
36-
and though they still seem to work you can get around that with a v1.14+ kubectl using: `kubectl apply -k variants/as-is/`.
38+
```
39+
kubectl create namespace kafka && \
40+
kubectl apply -k github.com/Yolean/kubernetes-kafka/variants/dev-small/?ref=storagclass-kustomize
41+
```
42+
43+
When all pods are Ready, test with for example `kafkacat -b localhost:9094 -L` over `kubectl -n kafka port-forward kafka-0 9094`.
3744

3845
### Maintaining your own kustomization
3946

40-
`kubectl apply -k` takes a single overlay, meaning that you can't compose different overlays from this repo.
41-
You'll probably want to maintain your own variant.
42-
One option is to keep kubernets-kafka as a git submodule and edit the relative path from an example variant.
47+
Start your variant as a new folder in your choice of version control, with a base `kustomization.yaml` pointing to a tag or revision in this repository:
48+
49+
```
50+
bases:
51+
- github.com/Yolean/kubernetes-kafka/rbac-namespace-default/?ref=553f327
52+
- github.com/Yolean/kubernetes-kafka/kafka/?ref=553f327
53+
- github.com/Yolean/kubernetes-kafka/zookeeper/?ref=553f327
54+
```
55+
56+
Then pick and chose from patches our [example variants](https://github.com/Yolean/kubernetes-kafka/tree/master/variants) to tailor your Kafka setup.
4357

4458
## Version history
4559

4660
| tag | k8s ≥ | highlights |
4761
| ------ | ----- | ----------- |
62+
| v6.0.0 | 1.11+ | Kafka 2.2.0 + `apply -k` (kubectl 1.14+) |
4863
| v5.1.0 | 1.11+ | Kafka 2.1.1 |
4964
| v5.0.3 | 1.11+ | Zookeeper fix [#227](https://github.com/Yolean/kubernetes-kafka/pull/227) + [maxClientCnxns=1](https://github.com/Yolean/kubernetes-kafka/pull/230#issuecomment-445953857) |
5065
| v5.0 | 1.11+ | Destabilize because in Docker we want Java 11 [#197](https://github.com/Yolean/kubernetes-kafka/pull/197) [#191](https://github.com/Yolean/kubernetes-kafka/pull/191) |
@@ -62,21 +77,14 @@ Have a look at:
6277
* [./consumers-prometheus](./consumers-prometheus/)
6378
* [or plain JMX](https://github.com/Yolean/kubernetes-kafka/pull/96)
6479
* what's happening in the [monitoring](https://github.com/Yolean/kubernetes-kafka/labels/monitoring) label.
65-
* Note that this repo is intentionally light on [automation](https://github.com/Yolean/kubernetes-kafka/labels/automation). We think every SRE team must build the operational knowledge first.
80+
* Note that this repo is intentionally light on [automation](https://github.com/Yolean/kubernetes-kafka/labels/automation). We think every SRE team must build the operational knowledge first. But there is an example of a [Cruise Control](./cruise-control/) setup.
6681

6782
## Outside (out-of-cluster) access
6883

6984
Available for:
7085

7186
* [Brokers](./outside-services/)
7287

73-
## Fewer than three nodes?
74-
75-
For [minikube](https://github.com/kubernetes/minikube/), [youkube](https://github.com/Yolean/youkube) etc:
76-
77-
* [Scale 1](https://github.com/Yolean/kubernetes-kafka/pull/44)
78-
* [Scale 2](https://github.com/Yolean/kubernetes-kafka/pull/118)
79-
8088
## Stream...
8189

8290
* [Kubernetes events to Kafka](./events-kube/)

configure/README.md

-5
This file was deleted.

configure/docker-storageclass-broker.yml

-6
This file was deleted.

configure/docker-storageclass-zookeeper.yml

-6
This file was deleted.

configure/minikube-storageclasses.yml

-21
This file was deleted.

kafka/50kafka.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ spec:
100100
name: data
101101
spec:
102102
accessModes: [ "ReadWriteOnce" ]
103-
storageClassName: kafka-broker
103+
storageClassName: standard
104104
resources:
105105
requests:
106106
storage: 10Gi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
resources:
2+
- node-reader.yml
3+
- pod-labler.yml
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bases:
2+
- ../scale-3-5
3+
resources:
4+
- aks-storageclass-broker-managed.yaml
5+
- aks-storageclass-zookeeper-managed.yaml
6+
patchesStrategicMerge:
7+
- volume-claims.yaml
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: StatefulSet
4+
metadata:
5+
name: kafka
6+
namespace: kafka
7+
spec:
8+
volumeClaimTemplates:
9+
- metadata:
10+
name: data
11+
spec:
12+
accessModes: [ "ReadWriteOnce" ]
13+
storageClassName: kafka-broker
14+
resources:
15+
requests:
16+
storage: 10Gi
17+
---
18+
apiVersion: apps/v1
19+
kind: StatefulSet
20+
metadata:
21+
name: pzoo
22+
namespace: kafka
23+
spec:
24+
volumeClaimTemplates:
25+
- metadata:
26+
name: data
27+
spec:
28+
accessModes: [ "ReadWriteOnce" ]
29+
storageClassName: kafka-zookeeper
30+
resources:
31+
requests:
32+
storage: 1Gi

variants/aws-gp2/kustomization.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bases:
2+
- ../scale-3-5
3+
resources:
4+
- aws-storageclass-broker-gp2.yaml
5+
- aws-storageclass-zookeeper-gp2.yaml
6+
patchesStrategicMerge:
7+
- volume-claims.yaml

variants/aws-gp2/volume-claims.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: StatefulSet
4+
metadata:
5+
name: kafka
6+
namespace: kafka
7+
spec:
8+
volumeClaimTemplates:
9+
- metadata:
10+
name: data
11+
spec:
12+
accessModes: [ "ReadWriteOnce" ]
13+
storageClassName: kafka-broker
14+
resources:
15+
requests:
16+
storage: 10Gi
17+
---
18+
apiVersion: apps/v1
19+
kind: StatefulSet
20+
metadata:
21+
name: pzoo
22+
namespace: kafka
23+
spec:
24+
volumeClaimTemplates:
25+
- metadata:
26+
name: data
27+
spec:
28+
accessModes: [ "ReadWriteOnce" ]
29+
storageClassName: kafka-zookeeper
30+
resources:
31+
requests:
32+
storage: 1Gi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
3+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "advertised.listeners=PLAINTEXT://:9092,OUTSIDE://localhost:9094"},
4+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
5+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "auto.create.topics.enable=true"},
6+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
7+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "num.partitions=1"}
8+
]

variants/dev-small/jmx-disable.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
name: kafka
5+
namespace: kafka
6+
spec:
7+
template:
8+
spec:
9+
containers:
10+
- name: broker
11+
env:
12+
- name: JMX_PORT
13+
value: ""

variants/dev-small/kustomization.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# With kubectl -n kafka port-forward kafka-0 9094
2+
bases:
3+
- ../scale-1-ephemeral
4+
patchesStrategicMerge:
5+
- jmx-disable.yaml
6+
patchesJson6902:
7+
# Currently these duplicate each others' directives to avoid an apply -k error: found conflict between different patches
8+
- target:
9+
group: apps
10+
version: v1
11+
kind: StatefulSet
12+
name: kafka
13+
path: listener-localhost.json
14+
- target:
15+
group: apps
16+
version: v1
17+
kind: StatefulSet
18+
name: kafka
19+
path: auto-create-topics.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
3+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "advertised.listeners=PLAINTEXT://:9092,OUTSIDE://localhost:9094"},
4+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
5+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "auto.create.topics.enable=true"},
6+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
7+
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "num.partitions=1"}
8+
]
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bases:
2+
- ../scale-3-5
3+
resources:
4+
- gke-storageclass-broker-pd.yaml
5+
- gke-storageclass-zookeeper-ssd.yaml
6+
- gke-storageclass-zookeeper-regional-euwest1cd-ssh.yaml
7+
patchesStrategicMerge:
8+
- volume-claims.yaml
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: StatefulSet
4+
metadata:
5+
name: kafka
6+
namespace: kafka
7+
spec:
8+
volumeClaimTemplates:
9+
- metadata:
10+
name: data
11+
spec:
12+
accessModes: [ "ReadWriteOnce" ]
13+
storageClassName: kafka-broker
14+
resources:
15+
requests:
16+
storage: 10Gi
17+
---
18+
apiVersion: apps/v1
19+
kind: StatefulSet
20+
metadata:
21+
name: pzoo
22+
namespace: kafka
23+
spec:
24+
volumeClaimTemplates:
25+
- metadata:
26+
name: data
27+
spec:
28+
accessModes: [ "ReadWriteOnce" ]
29+
storageClassName: kafka-zookeeper
30+
resources:
31+
requests:
32+
storage: 1Gi
33+
---
34+
apiVersion: apps/v1
35+
kind: StatefulSet
36+
metadata:
37+
name: zoo
38+
namespace: kafka
39+
spec:
40+
volumeClaimTemplates:
41+
- metadata:
42+
name: data
43+
spec:
44+
accessModes: [ "ReadWriteOnce" ]
45+
storageClassName: kafka-zookeeper-regional
46+
resources:
47+
requests:
48+
storage: 1Gi

variants/scale-1-ephemeral/kafka.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ metadata:
44
name: kafka
55
namespace: kafka
66
spec:
7-
replicas: 1
87
template:
98
spec:
109
volumes:
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
bases:
2-
- ../../kafka
3-
- ../../zookeeper
2+
- ../scale-1
43
patchesStrategicMerge:
54
- kafka.yaml
65
- zookeeper.yaml
7-
patchesJson6902:
8-
- target:
9-
group: apps
10-
version: v1
11-
kind: StatefulSet
12-
name: kafka
13-
path: kafka-scale1-overrides.json

variants/scale-1-ephemeral/zookeeper.yaml

+4-19
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,8 @@ metadata:
1111
name: pzoo
1212
namespace: kafka
1313
spec:
14-
replicas: 1
1514
template:
1615
spec:
17-
initContainers:
18-
- name: init-config
19-
env:
20-
- name: PZOO_REPLICAS
21-
value: '1'
22-
- name: ZOO_REPLICAS
23-
value: '0'
2416
volumes:
2517
- name: data
2618
emptyDir: {}
@@ -32,16 +24,9 @@ metadata:
3224
name: zoo
3325
namespace: kafka
3426
spec:
35-
replicas: 0
3627
template:
3728
spec:
38-
initContainers:
39-
- name: init-config
40-
env:
41-
# There's no validation on these numbers adding up to a coherent zk config, so watch out
42-
- name: PZOO_REPLICAS
43-
value: '1'
44-
- name: ZOO_REPLICAS
45-
value: '0'
46-
- name: ID_OFFSET
47-
value: '2'
29+
volumes:
30+
- name: data
31+
emptyDir: {}
32+
volumeClaimTemplates: []

variants/scale-1/kustomization.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
bases:
2+
- ../../rbac-namespace-default
23
- ../../kafka
34
- ../../zookeeper
45
patchesStrategicMerge:

0 commit comments

Comments
 (0)