Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kafka stacks locally through kubectl port-forward, in Docker #267

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions quickstart-kind.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
FROM busybox as entrypoint

RUN printf '#!/bin/sh\
# Brings up a kubernetes-kafka cluster in local docker. For example: \n\
#docker run -v /var/run/docker.sock:/var/run/docker.sock:rw --net=host --name kafka-quickstart -ti solsson/kubernetes-kafka:kind \n\
\n\
kind create cluster --name=$KIND_NAME \n\
echo KUBECONFIG=$KUBECONFIG \n\
kubectl cluster-info \n\
\n\
echo "To get local kubectl access (with --net=host) run for example:" \n\
echo "docker cp kafka-quickstart:/root/.kube/kind-config-$KIND_NAME ./kubeconfig-local-kubernetes-kafka" \n\
echo "export KUBECONFIG=\$(pwd)/kubeconfig-local-kubernetes-kafka" \n\
\n\
echo "Will now attempt an automated kafka setup ..." \n\
sleep 10 \n\
kubectl -n kube-system get pods \n\
kubectl wait --for=condition=Ready --timeout=120s -n kube-system pod --all \n\
\n\
kubectl apply -f 00-namespace.yml \n\
kubectl apply -f rbac-namespace-default/ \n\
kubectl apply -k variants/scale-1-ephemeral/ \n\
sleep 10 \n\
kubectl -n kafka get pods \n\
kubectl -n kafka wait --for=condition=Ready --timeout=120s pod/kafka-0 \n\
\n\
echo "Local kafka access requires a hosts file entry 127.0.0.1 kafka-0.broker.kafka.svc.cluster.local" \n\
echo "kubectl -n kafka port-forward kafka-0 9092" \n\
\n\
echo "To delete the cluster simply rm this container and $KIND_NAME-control-plane" \n\
'\
>> /entrypoint

FROM docker:18.09.5-dind@sha256:7ed03cb37cbe109867455393e670016149ae80fde931cf4773fabd8cf6284ee6 \
as docker

FROM lachlanevenson/k8s-kubectl:v1.14.1@sha256:8267b932d262f0fc2c901f515d7752dd9e7c60c8410086e7a9fda935bcc3ba0d \
as kubectl

FROM golang:1.12.4-alpine \
as kind

ENV KIND_VERSION=0.2.1
ENV GO111MODULE=on
RUN set -e; \
apk add --no-cache git; \
go get sigs.k8s.io/kind@${KIND_VERSION}

FROM alpine:3.9@sha256:28ef97b8686a0b5399129e9b763d5b7e5ff03576aa5580d6f4182a49c5fe1913 \
as runner

COPY --from=docker /usr/local/bin/docker /usr/local/bin/docker
COPY --from=kubectl /usr/local/bin/kubectl /usr/local/bin/kubectl
COPY --from=kind /go/bin/kind /usr/local/bin/kind

WORKDIR /kubernetes-kafka
COPY . .

ENV KIND_NAME=kafka KUBECONFIG=/root/.kube/kind-config-kafka

COPY --from=entrypoint /entrypoint /entrypoint
RUN chmod u+x /entrypoint

ENTRYPOINT ["/entrypoint"]
6 changes: 5 additions & 1 deletion variants/scale-1-ephemeral/kafka-scale1-overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "default.replication.factor=1"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "min.insync.replicas=1"}
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "min.insync.replicas=1"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "offsets.topic.replication.factor=1"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "offsets.topic.num.partitions=1"}
]
6 changes: 5 additions & 1 deletion variants/scale-1/kafka-scale1-overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "default.replication.factor=1"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "min.insync.replicas=1"}
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "min.insync.replicas=1"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "offsets.topic.replication.factor=1"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--override"},
{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "offsets.topic.num.partitions=1"}
]