Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Add support for cakeshop. (#55)
Browse files Browse the repository at this point in the history
* Adding support for cakeshop.
* Can now run cakeshop as a k8s deployment, by adding
```
cakeshop:
  version: latest
```
to the config file when generating the quorum K8s resources.
* Add docs and screen shots `docs/reouces/cakeshop.md`.
* Add example config `examples/config/cakeshop.yaml`.
* Note: kind does not easily support connecting to NodePorts, so minikube/docker desktop or a more complete K8s runtime is required.
  • Loading branch information
libby authored Aug 5, 2020
1 parent eb47794 commit f76b17c
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 0 deletions.
71 changes: 71 additions & 0 deletions docs/cakeshop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## Cakeshop Running In K8s

### Example Config
[cakeshop.yaml](../examples/config/cakeshop.yaml)

```yaml
# number of nodes to deploy
nodes:
number: 4
quorum:
quorum:
# supported: (raft | istanbul)
consensus: istanbul
Quorum_Version: 2.6.0
tm:
# (tessera|constellation)
Name: tessera
Tm_Version: 0.10.4
cakeshop:
version: latest
service:
type: NodePort
nodePort: 30108
```
## Generate The K8s Resources
```bash
$> docker run --rm -it -v $(pwd)/cakeshop.yaml:/qubernetes/cakeshop.yaml -v $(pwd)/out:/qubernetes/out quorumengineering/qubernetes ./qube-init cakeshop.yaml
```

## Deploy To K8s (Minikube or Other K8s runtime - not kind as kind does not support connecting to NodePorts easily)
```bash
$> kubectl apply -f out -f out/deployments
```

## Get The URL For The Cakeshop Deployment

```bash
$> kc get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cakeshop-service NodePort 10.110.202.50 <none> 8999:30108/TCP
```
## If Running minikube
* use `$(minikube ip):NodePort`, e.g. NodePort from above is `30108`
```bash
$> echo $(minikube ip):30108
192.168.64.25:30108
```

## If Running Docker Desktop K8s
* Your URL will be `localhost:NodePort`, e.g. `localhost:30108`

## Open In Browser And Select "Manage Nodes" (upper right corner)
![cakeshop-manage-nodes](resources/cakeshop-managed-node-ui.png)

## Get The Quorum Node URLs
```bash
$> kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
cakeshop-service NodePort 10.110.202.50 <none> 8999:30108/TCP 9m9s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 10h
quorum-node1 NodePort 10.101.38.95 <none> 9001:30239/TCP,9080:31461/TCP,8545:32321/TCP,8546:32293/TCP,30303:32559/TCP 9m9s
quorum-node2 NodePort 10.98.143.110 <none> 9001:31373/TCP,9080:30073/TCP,8545:30972/TCP,8546:30713/TCP,30303:32095/TCP 9m9s
quorum-node3 NodePort 10.99.63.70 <none> 9001:32161/TCP,9080:31576/TCP,8545:30497/TCP,8546:31440/TCP,30303:30180/TCP 9m9s
quorum-node4 NodePort 10.97.128.158 <none> 9001:31188/TCP,9080:30530/TCP,8545:30235/TCP,8546:31332/TCP,30303:31820/TCP 9m9s
```
![cakeshop-get-node-urls](resources/cake-k8s-get-node-urls.png)

## Add Nodes To Cakeshop
* Use the `CLUSTER-IP` and the cluster ports for geth (default `8545`) and tessera (default `9080`)
![cakeshop-add-node1](resources/cakeshop-add-node1.png)
Binary file added docs/resources/cake-k8s-get-node-urls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/resources/cakeshop-add-node1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/resources/cakeshop-managed-node-ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions qubernetes
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ if @config["prometheus"]
end
end

## deploy cakeshop as a deployment if enabled
puts "cakeshop"
puts ( @config["cakeshop"]["version"])
if @config["cakeshop"] and @config["cakeshop"]["version"]
File.open("out/07-cakeshop.yaml", "w") do |f|
f.puts (ERB.new(File.read(@base_template_path + "/cakeshop.yaml.erb"), nil, "-").result)
f.puts("---")
end
end

puts("\n")
puts " Success! ".green
puts("\n")
Expand Down
116 changes: 116 additions & 0 deletions templates/k8s/cakeshop.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<%-
@Cakeshop_Version = @config["cakeshop"]["version"]

# default quorumengineering/quorum
if @config["cakeshop"]["Docker_Repo"]
@Cakeshop_Docker_Repo = @config["cakeshop"]["Docker_Repo"]
else
@Cakeshop_Docker_Repo = "quorumengineering"
end
# NodePort | ClusterIP | Loadbalancer
# default to NodePort if not set
@Service_Type = "LoadBalancer"
if @config["cakeshop"] and @config["cakeshop"]["service"] and @config["cakeshop"]["service"]["type"]
@Service_Type = @config["cakeshop"]["service"]["type"]
end
-%>

kind: Service
apiVersion: v1
metadata:
name: cakeshop-service
labels:
app: cakeshop
spec:
# LoadBalancer is the default: Create an HA proxy in the cloud provider
# with an External IP address - *Only supported by some cloud providers*
# loadbalancer access via externalIp:port (8999)
# NodePort | ClusterIP | Loadbalancer
type: <%= @Service_Type %>
ports:
# Accept traffic sent to port 8080
- name: http
protocol: TCP
port: 8999
targetPort: 8080
<%- if @config["cakeshop"] and @config["cakeshop"] and @config["cakeshop"]["service"]["nodePort"] -%>
nodePort: <%= @config["cakeshop"]["service"]["nodePort"] %>
<%- end -%>
selector:
# Loadbalance traffic across Pods matching
# this label selector
app: cakeshop

---

apiVersion: apps/v1
kind: Deployment
metadata:
# Unique key of the Deployment instance
name: cakeshop-deployment
spec:
selector:
matchLabels:
app: cakeshop
replicas: 1
template:
metadata:
labels:
# Apply this label to pods and default
# the Deployment label selector to this value
app: cakeshop
spec:
containers:
- name: cakeshop
image: <%= @Cakeshop_Docker_Repo %>/cakeshop:<%= @Cakeshop_Version %>
imagePullPolicy: Always
env:
- name: JAVA_OPTS
value: "-Dgeth.auto.start=false -Dgeth.auto.stop=false"
ports:
- containerPort: 8999

<%-

if @config["cakeshop"] and @config["cakeshop"]["service"] and @config["cakeshop"]["service"]["Ingress"] then
@Ingress = true

if @config["cakeshop"]["service"]["Ingress"]["Host"] then
@Ingress_Host = @config["cakeshop"]["service"]["Ingress"]["Host"]
end

end

-%>

<%- if @Ingress -%>
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
<%= @Namespace %>
name: cakeshop-ingress
spec:
rules:
<%- if @Ingress_Host -%>
- host: "<%= @Ingress_Host %>"
http:
paths:
- path: /cakeshop
backend:
serviceName: cakeshop-service
servicePort: 8080
<%- else -%>
- http:
paths:
- path: /cakeshop
backend:
serviceName: cakeshop-service
servicePort: 8080
<%- end -%>
<%- if @Ingress_Host -%>
tls:
- hosts:
- "<%= @Ingress_Host %>"
<%- end -%>
<%- end -%>

0 comments on commit f76b17c

Please sign in to comment.