Kafka no zookeeper (#1493)

This commit is contained in:
erabii
2023-11-01 23:32:52 +02:00
committed by GitHub
parent edca796fda
commit c6f331f40b
7 changed files with 45 additions and 87 deletions

View File

@@ -91,7 +91,6 @@ class ConfigurationWatcherMultipleAppsIT {
@BeforeEach
void setup() {
util.zookeeper(NAMESPACE, Phase.CREATE);
util.kafka(NAMESPACE, Phase.CREATE);
appA(Phase.CREATE);
appB(Phase.CREATE);
@@ -100,7 +99,6 @@ class ConfigurationWatcherMultipleAppsIT {
@AfterEach
void afterEach() {
util.zookeeper(NAMESPACE, Phase.DELETE);
util.kafka(NAMESPACE, Phase.DELETE);
appA(Phase.DELETE);
appB(Phase.DELETE);

View File

@@ -76,8 +76,7 @@ class LoadBalancerIT {
private static final String SERVICE_URL = "http://localhost:80/loadbalancer-it/service";
private static final String SPRING_CLOUD_K8S_LOADBALANCER_APP_NAME =
"spring-cloud-kubernetes-k8s-client-loadbalancer";
private static final String SPRING_CLOUD_K8S_LOADBALANCER_APP_NAME = "spring-cloud-kubernetes-k8s-client-loadbalancer";
private static final String NAMESPACE = "default";
@@ -155,8 +154,8 @@ class LoadBalancerIT {
}
private static void patchForServiceMode() {
patchWithMerge("spring-cloud-kubernetes-k8s-client-loadbalancer", LoadBalancerIT.NAMESPACE,
BODY_FOR_MERGE, POD_LABELS);
patchWithMerge("spring-cloud-kubernetes-k8s-client-loadbalancer", LoadBalancerIT.NAMESPACE, BODY_FOR_MERGE,
POD_LABELS);
}
}

View File

@@ -232,11 +232,14 @@ public final class Util {
public void kafka(String namespace, Phase phase) {
V1Deployment deployment = (V1Deployment) yaml("kafka/kafka-deployment.yaml");
V1Service service = (V1Service) yaml("kafka/kafka-service.yaml");
V1ConfigMap configMap = (V1ConfigMap) yaml("kafka/kafka-configmap-startup-script.yaml");
if (phase.equals(Phase.CREATE)) {
createAndWait(namespace, configMap, null);
createAndWait(namespace, "kafka", deployment, service, null, false);
}
else if (phase.equals(Phase.DELETE)) {
deleteAndWait(namespace, configMap, null);
deleteAndWait(namespace, deployment, service, null);
}
}
@@ -253,18 +256,6 @@ public final class Util {
}
}
public void zookeeper(String namespace, Phase phase) {
V1Deployment deployment = (V1Deployment) yaml("zookeeper/zookeeper-deployment.yaml");
V1Service service = (V1Service) yaml("zookeeper/zookeeper-service.yaml");
if (phase.equals(Phase.CREATE)) {
createAndWait(namespace, "zookeeper", deployment, service, null, false);
}
else if (phase.equals(Phase.DELETE)) {
deleteAndWait(namespace, deployment, service, null);
}
}
/**
* reads a yaml from classpath, fails if not found.
*/

View File

@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: kafka-start-config-script
data:
kafka_start.sh: |
#!/bin/sh
sed -i '/KAFKA_ZOOKEEPER_CONNECT/d' /etc/confluent/docker/configure
sed -i 's/cub zk-ready/echo ignore zk-ready/' /etc/confluent/docker/ensure
KAFKA_CLUSTER_ID="$(kafka-storage random-uuid)"
echo "kafka-storage format --ignore-formatted -t $KAFKA_CLUSTER_ID -c /etc/kafka/kafka.properties" >> /etc/confluent/docker/ensure
/etc/confluent/docker/run

View File

@@ -21,34 +21,39 @@ spec:
# and this will cause this problem: https://github.com/confluentinc/cp-docker-images/blob/master/debian/kafka/include/etc/confluent/docker/configure#L58-L62
# Another solution is to rename the service.
enableServiceLinks: false
volumes:
- name: kafka-start-config-script
configMap:
name: kafka-start-config-script
defaultMode: 0744
containers:
- name: kafka
- name: kafka-start-config-script
volumeMounts:
- name: kafka-start-config-script
mountPath: /tmp
command:
- /tmp/./kafka_start.sh
image: confluentinc/cp-kafka:7.2.1
ports:
- containerPort: 9092
env:
- name: KAFKA_LISTENERS
value: "INTERNAL://0.0.0.0:9092,OUTSIDE://0.0.0.0:9094"
- name: KAFKA_BROKER_ID
value: "1"
- name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
value: "INTERNAL:PLAINTEXT,OUTSIDE:PLAINTEXT"
value: "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT"
- name: KAFKA_ADVERTISED_LISTENERS
value: "INTERNAL://kafka:9092,OUTSIDE://localhost:9094"
- name: KAFKA_INTER_BROKER_LISTENER_NAME
value: "INTERNAL"
- name: KAFKA_ADVERTISED_HOST_NAME
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: KAFKA_ZOOKEEPER_CONNECT
value: zookeeper:2181
# we have enabled auto creation of topics and when this happens there is a replication factor of 3
# that is set automatically. Since we don't have that many, producers will fail.
# This setting ensures that there is just one replication
value: "PLAINTEXT://kafka:9092"
- name: KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR
value: "1"
- name: KAFKA_PROCESS_ROLES
value: "broker,controller"
- name: KAFKA_NODE_ID
value: "1"
- name: KAFKA_LISTENERS
value: "PLAINTEXT://:9092,CONTROLLER://:9093"
- name: KAFKA_INTER_BROKER_LISTENER_NAME
value: "PLAINTEXT"
- name: KAFKA_CONTROLLER_LISTENER_NAMES
value: "CONTROLLER"
- name: KAFKA_CONTROLLER_QUORUM_VOTERS
value: "1@localhost:9093"

View File

@@ -1,31 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: kafka
component: zookeeper
name: zookeeper
spec:
replicas: 1
selector:
matchLabels:
app: kafka
component: zookeeper
template:
metadata:
labels:
app: kafka
component: zookeeper
spec:
containers:
- name: zookeeper
image: confluentinc/cp-zookeeper:7.2.1
ports:
- containerPort: 2181
env:
- name: ZOOKEEPER_ID
value: "1"
- name: ZOOKEEPER_SERVER_1
value: zookeeper
- name: ZOOKEEPER_CLIENT_PORT
value: 2181

View File

@@ -1,16 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: zookeeper
labels:
app: kafka
component: zookeeper
spec:
ports:
- port: 2181
name: zookeeper-port
targetPort: 2181
protocol: TCP
selector:
app: kafka
component: zookeeper