Skip to content

Commit

Permalink
Add development docs for Mesos
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Medzinski committed Apr 19, 2018
1 parent 93aa075 commit 93d8b24
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ OS := $(shell go env GOOS)
BUILD_DIR := build
LDFLAGS := -X main.version=$(VERSION)

.PHONY: all build lint lint-deps test integration-test
THIS_FILE := $(lastword $(MAKEFILE_LIST))
.PHONY: all build build-linux package clean lint lint-deps test integration-test

all: lint test build

build:
go build -v -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(NAME) ./cmd/$(NAME)

build-linux:
GOOS=linux $(MAKE) -f $(THIS_FILE) build

package: build
tar -czvf $(BUILD_DIR)/$(NAME)-$(VERSION)-$(OS)-$(ARCH).tar.gz -C $(BUILD_DIR) $(NAME)

Expand Down
37 changes: 33 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,14 @@ spec:

### Mesos

Registration based on data provided from Mesos is not supported yet!
Registration based on data provided from Mesos API is supported only partially.
Because Mesos API do not provide health check definions we are unable to sync
them with Consul agent.

## Development

### Kubernetes integration

To develop the hook locally you need the following things to be installed on
your machine:

Expand All @@ -171,7 +175,7 @@ When everything is installed and setup properly, you can build hook for the Linu
operating system (as Minikube starts Kubernetes cluster on Linux virtual machine):

```bash
GOARCH=amd64 GOOS=linux go build -v ./cmd/consul-registration-hook
make build-linux
```

After successful build, you can start your local mini Kubernetes cluster with
Expand All @@ -181,7 +185,7 @@ project root mounted to the Kubernetes virtual machine:
minikube start --mount --mount-string .:/hooks
```

### Simple usecase, consul agent in separate container in the pod
#### Simple usecase, consul agent in separate container in the pod

Create a pod with Consul agent in development mode and hooks mounted:

Expand All @@ -195,7 +199,7 @@ You can login to the container with hooks using the following command:
kubectl exec -it myservice-pod -- /bin/bash
```

### Consul ACL & DaemonSet usecase
#### Consul ACL & DaemonSet usecase

Create consul secret:

Expand All @@ -219,6 +223,30 @@ You can find the hook binary in `/hooks` folder on the container. All required
environment variables are set up so you can run a command without any additional
configuration.

### Mesos integration

To develop the hook locally you need the following things to be installed on
your machine:

* [Docker CE][10]
* [Go][6]

When everything is installed and setup properly, you can build hook for the Linux
operating system (we will use dockerized Mesos cluster for development):

```bash
make build-linux
```

After successful build, you can start your local Mesos + Marathon cluster:

```bash
docker-compose up
```

Hook binary is available on Mesos slave container in `/opt/consul-registration-hook/`
folder, and can be used directly when deploying apps using Marathon (localhost:8080).

[1]: https://www.consul.io/
[2]: https://kubernetes.io/
[3]: http://mesos.apache.org/
Expand All @@ -228,3 +256,4 @@ configuration.
[7]: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
[8]: https://kubernetes.io/docs/concepts/configuration/secret/
[9]: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
[10]: https://www.docker.com/get-docker
44 changes: 44 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
version: '3'
services:
zookeeper:
image: zookeeper
ports:
- 2181:2181
mesos-master:
image: mesosphere/mesos-master:1.5.0
ports:
- 5050:5050
environment:
- MESOS_PORT=5050
- MESOS_ZK=zk://zookeeper:2181/mesos
- MESOS_QUORUM=1
- MESOS_REGISTRY=in_memory
- MESOS_LOG_DIR=/var/log/mesos
- MESOS_WORK_DIR=/var/tmp/mesos
mesos-slave:
image: mesosphere/mesos-slave:1.5.0
privileged: true
ports:
- 5051:5051
environment:
- MESOS_PORT=5051
- MESOS_MASTER=zk://zookeeper:2181/mesos
- MESOS_SWITCH_USER=0
- MESOS_CONTAINERIZERS=mesos
- MESOS_LOG_DIR=/var/log/mesos
- MESOS_WORK_DIR=/var/tmp/mesos
- MESOS_SYSTEMD_ENABLE_SUPPORT=false
volumes:
- ./build:/opt/consul-registration-hook
marathon:
image: mesosphere/marathon:v1.6.352
ports:
- 8080:8080
environment:
- MARATHON_MASTER=zk://zookeeper:2181/mesos
- MARATHON_ZK=zk://zookeeper:2181/marathon
consul:
image: consul:1.0.7
ports:
- 8500:8500
command: consul agent -dev -client 0.0.0.0
4 changes: 2 additions & 2 deletions mesos/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ func (p *ServiceProvider) getExecutorAndFrameworkID() (executorID, frameworkID s
}

func (p *ServiceProvider) getMesosHostname() (string, error) {
hostname := os.Getenv("MESOS_HOSTNAME")
hostname := os.Getenv("HOST")
if hostname == "" {
return "", errors.New("missing MESOS_HOSTNAME environmental variable")
return "", errors.New("missing HOST environmental variable")
}
return hostname, nil
}
Expand Down

0 comments on commit 93d8b24

Please sign in to comment.