koding / kite

Micro-service framework in Go
https://godoc.org/github.com/koding/kite
MIT License
3.26k stars 300 forks source link

How to Let Dockerized Kites Register to Kontrol #223

Closed giuseppegreco closed 6 years ago

giuseppegreco commented 6 years ago

I've 3 kites, each dockerizied with its own container. The container running kontrol is fine as the first time the container is started, command kontrol -inital is executed and file kite.key created in folder ~/.kite. However, the containers running my own kites fail because file ~/.kite/kite.key doesn't exist. Does this mean I should run kontrol -inital in each container? How should I use kitectl to register my kites to kontrol, which is running on a different container?

I've read the documentation but it is not very clear to me (kitectl is not explained very extensively and I was unable to find at least a working example). I've tried this...

./kitectl register
Username: gonzo

but it doesn't work:

Starting new session failed. Want: 200 Got: 404

Any help would be really appreciated. Many thanks :-)

rjeczalik commented 6 years ago
$ kitectl register --help
Usage: kitectl register [options]

  Registers your host to a kite authority.
  If no server is specified, "https://discovery.koding.io/kite" is the default.

Options:

  -to=https://discovery.koding.io/kite  Kontrol URL
  -username=koding                      Username

You need to point kitectl at your kontrol container with -to flag. As to best practices for registering with kontrol, you should generate a kite.key for each of your app and inject it to each container.

giuseppegreco commented 6 years ago

Thanks it worked for me :-)

ralphking commented 5 years ago

Hi @giuseppegreco do you have some example Dockerfiles? I am struggling with this as well. Thanks

giuseppegreco commented 5 years ago

Here it is:

FROM golang:alpine as builder

RUN apk add --update --no-cache git RUN go get -u github.com/golang/dep/cmd/dep RUN go get -d github.com/koding/kite

WORKDIR ${GOPATH}/src/github.com/koding/kite

RUN mkdir /build RUN ${GOPATH}/bin/dep ensure RUN go build -o /build/kontrol ./kontrol/kontrol

FROM alpine ENV APP_HOME /opt/robotrader

WORKDIR ${APP_HOME}

ADD ./certs/* /certs/ ADD ./kontrol.sh . RUN chmod a+x ./kontrol.sh

COPY --from=builder /build/kontrol . CMD ["./kontrol.sh"]

kontrol.sh looks like this:

!/bin/sh

while ! nc -z etcd 2379; do sleep 3; done ./kontrol -initial ./kontrol

I hope it helps, j3d

On 25 Jan 2019, at 08:25, Ralph King notifications@github.com wrote:

Hi @giuseppegreco do you have some example Dockerfiles? I am struggling with this as well. Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ralphking commented 5 years ago

Thanks so much! Do you have one for one of your kites that is connecting? Showing how you are using kitetcl?

giuseppegreco commented 5 years ago

I use compose... and here’s my full file: version: '3.3'

services: etcd: image: 'quay.io/coreos/etcd' command: > etcd -name etcd -advertise-client-urls http://127.0.0.1:2379,http://127.0.0.1:4001 -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 -initial-advertise-peer-urls http://127.0.0.1:2380 -listen-peer-urls http://0.0.0.0:2380 healthcheck: test: ["CMD", "curl", "-f", "http://etcd:2379/version"] interval: '30s' timeout: '10s' retries: 5 networks: robotrader:

mongo: build: context: '.' dockerfile: 'Dockerfile.mongo' environment: MONGO_INITDB_DATABASE: 'robotrader' ports:

volumes: data-storage: kite-key:

networks: robotrader: And here’s the Dockerfike of one of my kites (the others are just very similar): FROM golang:alpine as builder

RUN apk add --update --no-cache git RUN go get -u github.com/golang/dep/cmd/dep

ADD ./base ${GOPATH}/src/github.com/agamura/robotrader/base ADD ./broker ${GOPATH}/src/github.com/agamura/robotrader/broker ADD ./config ${GOPATH}/src/github.com/agamura/robotrader/config ADD ./logging ${GOPATH}/src/github.com/agamura/robotrader/logging ADD ./utils ${GOPATH}/src/github.com/agamura/robotrader/utils

COPY ./Gopkg.lock ${GOPATH}/src/github.com/agamura/robotrader/Gopkg.lock COPY ./Gopkg.toml ${GOPATH}/src/github.com/agamura/robotrader/Gopkg.toml

WORKDIR ${GOPATH}/src/github.com/agamura/robotrader

RUN mkdir /build RUN ${GOPATH}/bin/dep ensure RUN go build -o /build/broker ./broker/broker

FROM alpine ARG config_file

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*

ENV APP_HOME /opt/robotrader WORKDIR ${APP_HOME}

ADD ./certs/* /certs/ COPY ./broker/config/${config_file} ./broker.toml COPY --from=builder /build/broker .

CMD ["./broker"]

Cheers, j3d

Sent from my iPhone

On 25 Jan 2019, at 09:09, Ralph King notifications@github.com wrote:

Thanks so much! Do you have one for one of your kites that is connecting? Showing how you are using kitetcl?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ralphking commented 5 years ago

Thank you!