Skip to content

Commit

Permalink
Add kind-based dev cluster
Browse files Browse the repository at this point in the history
This now uses kind to create a real dev setup with a NATS cluster and a
3-node Liftbridge cluster.

You'll need to download kind and skaffold to make this work.

Then do:
1. `make kind-up` to bring up the kind cluster
2. `make kind-apply` and then let it finish

It'll also expose both the Liftbridge nodes as well as the NATS board
on local ports so you can run the examples against that cluster.
  • Loading branch information
annismckenzie committed Oct 29, 2019
1 parent 397fc19 commit 26e58ce
Show file tree
Hide file tree
Showing 20 changed files with 520 additions and 6 deletions.
1 change: 1 addition & 0 deletions .dockerignore
@@ -0,0 +1 @@
dev/data
18 changes: 15 additions & 3 deletions Makefile
Expand Up @@ -2,9 +2,8 @@

GITREF = `git rev-list HEAD |head -n 1`
CI_COMMIT_REF_SLUG = `git rev-parse --abbrev-ref HEAD`

export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
NAME=kind
KUBECONFIG:=~/.kube/kind-config-$(NAME)

dev:
@ cd dev/; docker-compose up --build
Expand All @@ -14,3 +13,16 @@ build-dev-image:

build-image:
@ docker build -t "liftbridge/liftbridge:$(CI_COMMIT_REF_SLUG)" -t "liftbridge/liftbridge:$(GITREF)" -f Dockerfile .

kind-up:
kind create cluster --config k8s/dev/kind.yaml --name=$(NAME)

kind-down:
kind delete cluster --name=$(NAME)

kind-apply:
@ KUBECONFIG=$(KUBECONFIG) kubectl apply -R -f k8s/dev/nats-operator.yaml
@ KUBECONFIG=$(KUBECONFIG) skaffold dev -p dev

kind-export:
@echo export KUBECONFIG="$$(kind get kubeconfig-path --name="$(NAME)")"
1 change: 1 addition & 0 deletions dev/Dockerfile.compose
Expand Up @@ -6,6 +6,7 @@ ENV GO111MODULE on
ENV CGO_ENABLED 1
ENV GOARCH amd64
ENV GOOS linux
RUN go mod download
RUN go build -mod=readonly -race -o liftbridge

FROM debian:stretch-slim
Expand Down
4 changes: 1 addition & 3 deletions dev/docker-compose.yml
Expand Up @@ -31,7 +31,7 @@ services:
'--port=9292',
'--level=debug',
'--nats-servers=nats:4222',
'--raft-bootstrap-peers=server-1,server-2',
'--raft-bootstrap-seed',
'--id=server-1'
]
environment:
Expand Down Expand Up @@ -87,8 +87,6 @@ services:
- overlay
volumes:
- ./data/data3:/data3
volumes:
build-cache:
networks:
overlay:
driver: bridge
18 changes: 18 additions & 0 deletions k8s/base/config.yaml
@@ -0,0 +1,18 @@
apiVersion: v1
data:
liftbridge.conf: |
listen: 0.0.0.0:9292
# data.dir: /tmp/liftbridge/server-2
# log.level: debug
clustering {
min.insync.replicas: 1
}
kind: ConfigMap
metadata:
labels:
app: liftbridge
component: config
environment: dev
k8s-app: liftbridge
name: config
7 changes: 7 additions & 0 deletions k8s/base/kustomization.yaml
@@ -0,0 +1,7 @@
---
namespace: default

resources:
- svc.yaml
- statefulset.yaml
- config.yaml
40 changes: 40 additions & 0 deletions k8s/base/statefulset.yaml
@@ -0,0 +1,40 @@
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: liftbridge
spec:
serviceName: "liftbridge-headless"
replicas: 3
selector:
matchLabels:
app: liftbridge
template:
metadata:
labels:
app: liftbridge
spec:
containers:
- name: liftbridge
image: liftbridge
ports:
- name: grpc
containerPort: 9292
volumeMounts:
- name: liftbridge-data
mountPath: /data
- mountPath: /etc/liftbridge.conf
name: config
subPath: liftbridge.conf
volumes:
- configMap:
name: config
name: config
volumeClaimTemplates:
- metadata:
name: liftbridge-data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 5Gi
27 changes: 27 additions & 0 deletions k8s/base/svc.yaml
@@ -0,0 +1,27 @@
---
apiVersion: v1
kind: Service
metadata:
name: liftbridge-headless
spec:
selector:
app: liftbridge
clusterIP: "None"
ports:
- name: grpc
protocol: TCP
port: 9292
targetPort: grpc
---
apiVersion: v1
kind: Service
metadata:
name: liftbridge
spec:
selector:
app: liftbridge
ports:
- name: grpc
protocol: TCP
port: 9292
targetPort: grpc
25 changes: 25 additions & 0 deletions k8s/dev/Dockerfile.kind
@@ -0,0 +1,25 @@
FROM golang:1.13-alpine as build-base
RUN apk update && apk upgrade && \
apk add --no-cache bash git openssh make bzr
WORKDIR /workspace
ENV GO111MODULE on

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY server/ server/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -mod=readonly -o liftbridge

FROM alpine:latest
RUN apk update && apk add --no-cache bash
COPY --from=build-base /workspace/liftbridge /usr/local/bin/liftbridge
COPY k8s/dev/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
1 change: 1 addition & 0 deletions dev/Dockerfile.natsboard → k8s/dev/Dockerfile.natsboard
Expand Up @@ -3,3 +3,4 @@ FROM mhart/alpine-node:12
RUN npm install natsboard -g
RUN apk add --no-cache netcat-openbsd
COPY wait-for.sh /wait-for.sh
ENTRYPOINT ["/wait-for.sh"]
10 changes: 10 additions & 0 deletions k8s/dev/entrypoint.sh
@@ -0,0 +1,10 @@
#!/bin/bash

if [ "$HOSTNAME" = "liftbridge-0" ]
then
echo "Running in liftbridge-0 as a bootstrap seed...\n"
liftbridge --data-dir=/data --config /etc/liftbridge.conf --level=debug --nats-servers=nats://nats.liftbridge.svc:4222 --raft-bootstrap-seed --id="$HOSTNAME"
else
echo "Running in $HOSTNAME...\n"
liftbridge --data-dir=/data --config /etc/liftbridge.conf --level=debug --nats-servers=nats://nats.liftbridge.svc:4222 --raft-bootstrap-peers=liftbridge-0 --id="$HOSTNAME"
fi
23 changes: 23 additions & 0 deletions k8s/dev/kind.yaml
@@ -0,0 +1,23 @@
---
kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 32767
hostPort: 9292
listenAddress: "0.0.0.0"
- containerPort: 32767
hostPort: 9293
listenAddress: "0.0.0.0"
- containerPort: 32767
hostPort: 9294
listenAddress: "0.0.0.0"
- containerPort: 32766
hostPort: 3000
listenAddress: "0.0.0.0"
- containerPort: 32765
hostPort: 4222
listenAddress: "0.0.0.0"
- role: worker
- role: worker
11 changes: 11 additions & 0 deletions k8s/dev/kustomization.yaml
@@ -0,0 +1,11 @@
---
namespace: liftbridge

bases:
- ../base

resources:
- namespace.yaml
- nats.yaml
- natsboard.yaml
- svc.yaml
8 changes: 8 additions & 0 deletions k8s/dev/namespace.yaml
@@ -0,0 +1,8 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: liftbridge
labels:
name: liftbridge
environment: dev

0 comments on commit 26e58ce

Please sign in to comment.