Skip to content

Commit

Permalink
devenv: add browseable option to _run/kind
Browse files Browse the repository at this point in the history
Add an option to proxy localhost:80 to your app
to play nice with kubernetes ingresses.
  • Loading branch information
boz committed Jun 24, 2020
1 parent 25dfeb4 commit 8d399ba
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
2 changes: 1 addition & 1 deletion _run/common.mk
@@ -1,6 +1,6 @@
include ../common-base.mk

DATA_ROOT := $(PWD)/cache
DATA_ROOT := ./cache
NODE_HOME := $(DATA_ROOT)/node
CLIENT_HOME := $(DATA_ROOT)/client

Expand Down
6 changes: 3 additions & 3 deletions _run/kube/Makefile
Expand Up @@ -17,8 +17,8 @@ provider-run:
provider-status:
curl -s "$(GATEWAY_ENDPOINT)/status" | jq

.PHONY: provider-send-manifest
provider-send-manifest:
.PHONY: send-manifest
send-manifest:
$(AKASHCTL) provider send-manifest "$(SDL_PATH)" \
--owner "$(KEY_ADDRESS)" \
--dseq "$(DSEQ)" \
Expand All @@ -34,4 +34,4 @@ provider-lease-status:

.PHONY: provider-lease-ping
provider-lease-ping:
curl -sIH "Host: hello.localhost" localhost:8081
curl -sIH "Host: hello.localhost" localhost:$(KIND_HTTP_PORT)
29 changes: 27 additions & 2 deletions _run/kube/README.md
Expand Up @@ -66,13 +66,35 @@ make clean kind-cluster-clean init

### Initialize

Start and initialize kind
Start and initialize kind.

Kubernetes ingress objects present some difficulties for creating development
environments. Two options are offered below - the first (random port) is less error-prone
and can have multiple instances run concurrently, while the second option arguably
has a better payoff.

**note**: this step waits for kubernetes metrics to be available, which can take some time.
The counter on the left side of the messages is regularly in the 120 range. If it goes beyond 250,
there may be a problem.

#### Map a random local port to port 80 of your workload

This is less error-prone, but makes it difficult to access your app through the browser.

__t1__
```sh
make kind-cluster-create
```

#### Map local port 80 to to port 80 of your workload

If anything else is listening on port 80 (any other web server), this method
will fail. If it does succeed, you will be able to browse your app from the browser.

```sh
KIND_CONFIG=kind-config-80.yaml make kind-cluster-create
```

Build Akash binaries and initialize network

__t1__
Expand Down Expand Up @@ -190,7 +212,7 @@ workload configuration to that provider by sending it the manifest:

__t1__
```sh
make deployment-send-manifest
make send-manifest
```

You can check the status of your deployment with:
Expand All @@ -206,6 +228,9 @@ __t1__
make provider-lease-ping
```

If you chose to use port 80 when setting up kind, you can browse to your
deployed workload at http://hello.localhost

### Terminate lease

There are a number of ways that a lease can be terminated.
Expand Down
14 changes: 14 additions & 0 deletions _run/kube/kind-config-80.yaml
@@ -0,0 +1,14 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
6 changes: 0 additions & 6 deletions _run/kube/kind-config.yaml
Expand Up @@ -10,10 +10,4 @@ nodes:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
# todo: comment below
hostPort: 8081
protocol: TCP
# - containerPort: 443
# todo: comment below
# hostPort: 443
# protocol: TCP
5 changes: 3 additions & 2 deletions _run/kube/kind.mk
Expand Up @@ -4,6 +4,8 @@ KIND_HTTP_PORT = $(shell docker inspect \
--type container "$(KIND_NAME)-control-plane" \
--format '{{index .HostConfig.PortBindings "80/tcp" 0 "HostPort"}}')

KIND_CONFIG ?= kind-config.yaml

PROVIDER_HOSTNAME ?= localhost
PROVIDER_HOST ?= $(PROVIDER_HOSTNAME):$(KIND_HTTP_PORT)
PROVIDER_ENDPOINT ?= http://$(PROVIDER_HOST)
Expand All @@ -12,12 +14,11 @@ INGRESS_CONFIG_PATH ?= https://raw.githubusercontent.com/kubernetes/ingress-ngin

kind-port:
echo $(KIND_HTTP_PORT)
echo $(KIND_PORT)

.PHONY: kind-cluster-create
kind-cluster-create:
kind create cluster \
--config kind-config.yaml \
--config "$(KIND_CONFIG)" \
--name "$(KIND_NAME)"
kubectl apply -f "$(INGRESS_CONFIG_PATH)"
"$(AKASH_ROOT)/script/setup-kind.sh"
Expand Down

0 comments on commit 8d399ba

Please sign in to comment.