Skip to content

Commit

Permalink
devenv: _run/kube
Browse files Browse the repository at this point in the history
Checkpoint on `_run/kube` dev environment.

* `_run/lite`: update readme
* `_run/lite`: increase lease price
* `_run/kube`: update readme
* `_run/kube`: configure, use `kind` to deploy apps
* `provider/service`: fix NPE.

fixes #695
fixes #620
  • Loading branch information
boz committed Jun 23, 2020
1 parent 2b207df commit 25dfeb4
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 93 deletions.
36 changes: 30 additions & 6 deletions _run/kube/Makefile
@@ -1,13 +1,37 @@
include ../common.mk
include ../common-commands.mk
include kind.mk

GATEWAY_HOST ?= localhost:8080
GATEWAY_ENDPOINT ?= http://$(GATEWAY_HOST)

.PHONY: provider-run
provider-run:
$(AKASHCTL) $(KEY_OPTS) provider run \
--from "$(PROVIDER_KEY_NAME)" \
--cluster-k8s
AKASH_DEPLOYMENT_INGRESS_STATIC_HOSTS="false" \
$(AKASHCTL) $(KEY_OPTS) provider run \
--from "$(PROVIDER_KEY_NAME)" \
--cluster-k8s \
--gateway-listen-address "$(GATEWAY_HOST)"

.PHONY: provider-status
provider-status:
curl -s http://localhost:8080/status | jq
curl -s "$(GATEWAY_ENDPOINT)/status" | jq

.PHONY: provider-send-manifest
provider-send-manifest:
$(AKASHCTL) provider send-manifest "$(SDL_PATH)" \
--owner "$(KEY_ADDRESS)" \
--dseq "$(DSEQ)" \
--gseq "$(GSEQ)" \
--oseq "$(OSEQ)" \
--provider "$(PROVIDER_ADDRESS)"

.PHONY: provider-lease-status
provider-lease-status:
curl -s \
"$(GATEWAY_ENDPOINT)/lease/$(KEY_ADDRESS)/$(DSEQ)/$(GSEQ)/$(OSEQ)/$(PROVIDER_ADDRESS)/status" | \
jq

send-to-main:
$(akashctl) tx send $(OTHR_ADDR) $(MAIN_ADDR) 117akash $(KEY_OPTS) $(CHAIN_OPTS) --memo "send monies to main" -y --fees 10akash --trace
.PHONY: provider-lease-ping
provider-lease-ping:
curl -sIH "Host: hello.localhost" localhost:8081
233 changes: 158 additions & 75 deletions _run/kube/README.md
@@ -1,4 +1,24 @@
# Akash: Single-Node Local Setup with Minikube
# Dev Environment: "Kube" configuration

The _Kube_ dev environment builds:

* A single-node blockchain network
* An Akash Provider Services Daemon (PSD) for bidding and running workloads.
* A Kubernetes cluster for the PSD to run workloads on.

The [instructions](#runbook) below will illustrate how to:

* [Initialize blockchain node and client](#initialize)
* [Run a single-node network](#run-local-network)
* [Query objects on the network](#run-query)
* [Create a provider](#create-a-provider)
* [Run provider services](#run-provider-services)
* [Create a deployment](#create-a-deployment)
* [Bid on an order](#create-a-bid)
* [Terminate a lease](#terminate-lease)

See [commands](#commands) for a full list of utilities meant
for interacting with the network.

Run a network with a single, local node and execute workloads in Minikube.

Expand All @@ -7,143 +27,206 @@ Each command is marked __t1__-__t4__ to indicate a suggested terminal number.

## Setup

__t1__: Start and initialize minikube
Four keys and accounts are created. The key names are:

|Key Name|Use|
|---|---|
|`main`|Primary account (creating deployments, etc...)|
|`provider`|The provider account (bidding on orders, etc...)|
|`validator`|The sole validator for the created network|
|`other`|Misc. account to (receives tokens, etc...)|

Most `make` commands are configurable and have defaults to make it
such that you don't need to override them for a simple pass-through of
this example.

|Name|Default|Description|
|---|---|---|
|`KEY_NAME`|`main`|standard key name|
|`PROVIDER_KEY_NAME`|`provider`|name of key to use for provider|
|`DSEQ`|1|deployment sequence|
|`GSEQ`|1|group sequence|
|`OSEQ`|1|order sequence|
|`PRICE`|10akash|price to bid|

## Runbook

The following steps will bring up a network and allow for interacting
with it.

Running through the entire runbook requires four terminals.
Each command is marked __t1__-__t3__ to indicate a suggested terminal number.

If at any time you'd like to start over with a fresh chain, simply run:

__t1__
```sh
$ make minikube
$ minikube addons enable ingress
$ minikube addons enable metrics-server
make clean kind-cluster-clean init
```

__t1__: Build binaries
### Initialize

Start and initialize kind

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

__t1__: Initialize environment
Build Akash binaries and initialize network

__t1__
```sh
$ make init
make init
```
Creates various accounts, genesis file, configuration, and account keys stored in the `test` keyring.

## Start Network
### Run local network

In a separate terminal, the following command will run the `akashd` node:

__t2__: Run `akashd`
__t2__
```sh
$ make run-daemon
make node-run
```

You can check the status of the network with:

__t1__
```sh
make provider
make node-status
```

You should see blocks being produced - the block height should be increasing.

You can now view genesis accounts that were created:

__t1__
```sh
make run-provider
make query-accounts
```

### Create a provider

Create a provider on the network with the following command:

__t1__
```sh
make provider-status
make provider-create
```

View the on-chain representation of the provider with:

__t1__
```sh
make deploy
make query-provider
```

### Run provider services

In a separate terminal, run the following command

__t3__
```sh
make provider-status
make provider-run
```

Query the provider service gateway for its status:

__t1__
```sh
make provider-status
```
../../akashctl --home cache/client provider send-manifest deployment.yaml --owner "akash1r72zrnqd6t7kk6euwfslwccj7pz8s3ez4lmmt5" --dseq 620 --gseq 1 --oseq 1 --provider "akash1czw297jwpk8dymjqzzwduqchwwvh2k3l6zggn3"
```

__t1__: See status of accounts created, market orders, providers, and deployments.
### Create a deployment

Create a deployment from the `main` account with:

__t1__
```sh
$ make query-status
make deployment-create
```

## Transfer Tokens
This particular deployment is created from the sdl file in this directory ([`deployment.yaml`](deployment.yaml)).

__t1__: Send tokens to the _main_ account from _other_
Example of transfering tokens from one account to another.
Check that the deployment was created. Take note of the `dseq` - deployment sequence:

__t1__
```sh
$ make send-to-main
make query-deployments
```
Transfers `117akash` to the `main` account from `other` account.

__t1__: Query Transaction status
Note the `txhash` from the output of `make send-to-main` command above; use it to set the `TXN=<txhash>` value.
After a short time, you should see an order created for this deployment with the following command:

__t1__
```sh
$ TXN=37E016553DFC9305E8B56D5A8A9EA7E00B9CD6BF860055F7EDC1A2CE3ABCC6EE make query-txn
make query-orders
```
Displays information and status of the transaction. Useful for debugging why a transaction failed to execute.

__t1__: Query _master_ account
The Provider Services Daemon should see this order and bid on it.

__t1__
```sh
$ NAME=main make query-account
make query-bids
```

## Marketplace
And when the order is ready to be matched, a lease will be created:

__t3__: Query the market
__t1__
```sh
$ make query-status
make query-leases
```

__t4__: Create provider
You should now see "pending" inventory inventory in the provider status:

__t1__
```sh
$ make provider-create
make provider-status
```

__t1__: Query the created provider
### Distribute Manifest

Now that you have a lease with a provider, you need to send your
workload configuration to that provider by sending it the manifest:

__t1__
```sh
$ make provider-get
make deployment-send-manifest
```

__t1__: Create Deployment
You can check the status of your deployment with:

__t1__
```sh
$ make deploy
make provider-lease-status
```
Then view the order created from the deployment via `make query-market` or in __t3__. There will be a new Order created.

Bid on the new Order by referencing its sequence IDs:
You can reach your app with the following (Note: `Host:` header tomfoolery abound)
__t1__
```sh
../../akashctl --home cache/client query market order list
{
"id": {
"owner": "akash169zth98pgdq8ju0whzvg7zevzaahcvkutsv2sf",
"dseq": "2010",
"gseq": 1,
"oseq": 1,
...
make provider-lease-ping
```

Use the `dseq`, `gseq`, and `oseq` variables to configure the `make bid` command. eg:
### Terminate lease

There are a number of ways that a lease can be terminated.

`DSEQ=2010 GSEQ=1 OSEQ=1 PRICE=2akash make bid` will place a Bid on the Order. This will inform the running Provider to create a Lease if won.
#### Provider closes the bid:

__t1__
```sh
make bid-close
```
../../akashctl --home cache/client query market lease list
[
{
"id": {
"owner": "akash169zth98pgdq8ju0whzvg7zevzaahcvkutsv2sf",
"dseq": "2010",
"gseq": 1,
"oseq": 1,
"provider": "akash1caq7dslu2uc3gjg5ys3ulrc8u56k8f6jfm30m3"
},
"state": 1,
"price": {
"denom": "akash",
"amount": "2"
}
}
]

#### Tenant closes the order

__t1__
```sh
make order-close
```

TODO: Provider picking up and running Lease...
#### Tenant closes the deployment

__t1__: Ping workload
TODO: Update
__t1__
```sh
$ make ping
make deployment-close
```
5 changes: 2 additions & 3 deletions _run/kube/deployment.yaml
Expand Up @@ -8,8 +8,7 @@ services:
- port: 80
as: 80
accept:
- hello.192.168.99.100.nip.io
- hello.192.168.99.101.nip.io
- hello.localhost
to:
- global: true

Expand All @@ -26,7 +25,7 @@ profiles:
pricing:
web:
denom: akash
amount: 2
amount: 1000

deployment:
web:
Expand Down
19 changes: 19 additions & 0 deletions _run/kube/kind-config.yaml
@@ -0,0 +1,19 @@
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
# todo: comment below
hostPort: 8081
protocol: TCP
# - containerPort: 443
# todo: comment below
# hostPort: 443
# protocol: TCP

0 comments on commit 25dfeb4

Please sign in to comment.