Skip to content

Commit

Permalink
Merge pull request Andrew-Klaas#4 from Andrew-Klaas/go-movies-app
Browse files Browse the repository at this point in the history
adding "go-movies-app" (Consul ingress and L7 traffic management demo)
  • Loading branch information
Andrew-Klaas authored Jul 28, 2020
2 parents b5bb301 + d150ab2 commit 0cf16cb
Show file tree
Hide file tree
Showing 17 changed files with 895 additions and 17 deletions.
20 changes: 8 additions & 12 deletions demo/consul/consul.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
set -v

echo "Installing Consul from Helm chart repo..."
rm -rf ./consul-helm
git clone https://github.com/hashicorp/consul-helm.git
cd consul-helm; git checkout master ; cd ..
helm install consul -f ./values.yaml ./consul-helm
helm install consul hashicorp/consul -f values.yaml --version=0.23.1

sleep 10s
kubectl wait --timeout=180s --for=condition=Ready $(kubectl get pod --selector=app=consul -o name)
sleep 1s

cat <<EOF | kubectl apply -f -
apiVersion: v1
Expand All @@ -22,16 +20,14 @@ data:
{"consul": ["$(kubectl get svc consul-consul-dns -o jsonpath='{.spec.clusterIP}')"]}
EOF

sleep 10s

nohup kubectl port-forward service/consul-consul-ui 8500:80 --pod-running-timeout=10m &

kubectl wait --timeout=180s --for=condition=Ready $(kubectl get pod --selector=app=consul -o name)

sleep 10s
sleep 1s

#Configure ingress gateway to transit/transform app
consul config write k8s-transit-app.hcl
# consul config write ingress.hcl
# consul config write router.hcl
# consul config write splitter.hcl
# consul config write resolver.hcl

echo ""
echo -n "Your Consul UI is at: http://localhost:8500"
Expand Down
9 changes: 9 additions & 0 deletions demo/consul/k8s-transit-app.hcl → demo/consul/ingress.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,14 @@ Listeners = [
Name = "k8s-transit-app"
}
]
},
{
Port = 8080
Protocol = "http"
Services = [
{
Name = "go-movies-app"
}
]
}
]
11 changes: 11 additions & 0 deletions demo/consul/resolver.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
kind = "service-resolver"
name = "go-movies-app"
default_subset = "v1"
subsets = {
"v1" = {
filter = "v1 in Service.Tags"
}
"v2" = {
filter = "v2 in Service.Tags"
}
}
37 changes: 37 additions & 0 deletions demo/consul/router-headers.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Kind = "service-router"
Name = "go-movies-app"
Routes = [
{
Match {
HTTP {
Header = [
{
Name = "x-debug"
Exact = "1"
},
]
}
}
Destination {
Service = "go-movies-app"
ServiceSubset = "v1"
}
},
{
Match {
HTTP {
header = [
{
Name = "x-debug"
Exact = "2"
},
]
}
}
Destination {
Service = "go-movies-app"
ServiceSubset = "v2"
}
},
# NOTE: a default catch-all will send unmatched traffic to "web"
]
27 changes: 27 additions & 0 deletions demo/consul/router-path.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Kind = "service-router"
Name = "go-movies-app"
Routes = [
{
Match {
HTTP {
PathPrefix = "/v1"
}
}
Destination {
Service = "go-movies-app"
ServiceSubset = "v1"
}
},
{
Match {
HTTP {
PathPrefix = "/v2"
}
}
Destination {
Service = "go-movies-app"
ServiceSubset = "v2"
}
},
# NOTE: a default catch-all will send unmatched traffic to "web"
]
36 changes: 36 additions & 0 deletions demo/consul/router.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
kind = "service-router"
name = "go-movies-app"
routes = [
{
match {
http {
query_param = [
{
name = "x-version"
exact = "1"
},
]
}
}
destination {
service = "go-movies-app"
service_subset = "v1"
}
},
{
match {
http {
query_param = [
{
name = "x-version"
exact = "2"
},
]
}
}
destination {
service = "go-movies-app"
service_subset = "v2"
}
}
]
12 changes: 12 additions & 0 deletions demo/consul/splitter.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind = "service-splitter"
name = "go-movies-app"
splits = [
{
weight = 50
service_subset = "v1"
},
{
weight = 50
service_subset = "v2"
},
]
2 changes: 2 additions & 0 deletions demo/consul/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,8 @@ ingressGateways:
ports:
- port: 5000
nodePort: null
- port: 8080
nodePort: null

# Annotations to apply to the ingress gateway service. Annotations defined
# here will be applied to all ingress gateway services in addition to any
Expand Down
22 changes: 22 additions & 0 deletions demo/full_stack_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ LICENSE=$(cat $1)

#REQUIRES HELM 3
helm repo add stable https://kubernetes-charts.storage.googleapis.com/
helm repo add hashicorp https://helm.releases.hashicorp.com
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update

cd consul
Expand All @@ -24,6 +26,12 @@ cd ..
kubectl wait --timeout=180s --for=condition=Ready $(kubectl get pod --selector=app=mariadb -o name)
sleep 1s

cd postgresql
./postgresql.sh
cd ..
kubectl wait --timeout=180s --for=condition=Ready $(kubectl get pod --selector=app=pq -o name)
sleep 1s

cd vault
./vault.sh
sleep 5s
Expand All @@ -34,6 +42,20 @@ sleep 5s
kubectl apply -f ./application_deploy_sidecar
kubectl get svc k8s-transit-app

# kubectl apply -f ./go_movies_app/go_deploy_v1.yaml
# kubectl apply -f ./go_movies_app/go_svc.yaml
#kubectl apply -f ./go_movies_app/go_deploy_v2.yaml
kubectl apply -f ./go_movies_app

kubectl get svc go-movies-app

kubectl wait --timeout=180s --for=condition=Ready $(kubectl get pod --selector=app=go-movies-app -o name)

consul config write consul/ingress.hcl
consul config write consul/resolver.hcl
consul config write consul/splitter.hcl
consul config write consul/router-headers.hcl

echo ""
echo "use the following command to get your demo IP, port is 5000"
echo "$ kubectl get svc k8s-transit-app"
34 changes: 34 additions & 0 deletions demo/go_movies_app/go_deploy_v1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: go-movies-app-v1
labels:
app: go-movies-app
version: v1
spec:
replicas: 1
selector:
matchLabels:
app: go-movies-app
version: v1
template:
metadata:
annotations:
consul.hashicorp.com/connect-inject: "true"
consul.hashicorp.com/connect-service-protocol: "http"
"consul.hashicorp.com/service-tags": "v1"
consul.hashicorp.com/connect-service-upstreams: "vault:8200, pq-postgresql:5432"
name: go-movies-app
labels:
app: go-movies-app
version: v1
spec:
#fix: go-movies-app
serviceAccountName: vault-auth
automountServiceAccountToken: true
containers:
- name: go-movies-app
image: aklaas2/go-movies-app:latest
ports:
- containerPort: 8080
protocol: TCP
34 changes: 34 additions & 0 deletions demo/go_movies_app/go_deploy_v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: go-movies-app-v2
labels:
app: go-movies-app
version: v2
spec:
replicas: 1
selector:
matchLabels:
app: go-movies-app
version: v2
template:
metadata:
annotations:
consul.hashicorp.com/connect-inject: "true"
consul.hashicorp.com/connect-service-protocol: "http"
"consul.hashicorp.com/service-tags": "v2"
consul.hashicorp.com/connect-service-upstreams: "vault:8200, pq-postgresql:5432"
name: go-movies-app
labels:
app: go-movies-app
version: v2
spec:
#fix: go-movies-app
serviceAccountName: vault-auth
automountServiceAccountToken: true
containers:
- name: go-movies-app
image: aklaas2/go-movies-app-v2:latest
ports:
- containerPort: 8080
protocol: TCP
13 changes: 13 additions & 0 deletions demo/go_movies_app/go_svc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: Service
apiVersion: v1
metadata:
name: go-movies-app
spec:
selector:
app: go-movies-app
version: v1
ports:
- protocol: TCP
port: 8080
targetPort: 8080
type: LoadBalancer
13 changes: 13 additions & 0 deletions demo/go_movies_app/go_svc_v2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
kind: Service
apiVersion: v1
metadata:
name: go-movies-app-v2
spec:
selector:
app: go-movies-app
version: v2
ports:
- protocol: TCP
port: 8080
targetPort: 8080
type: LoadBalancer
5 changes: 5 additions & 0 deletions demo/postgresql/postgresql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

helm install pq \
--set postgresqlPassword=password,postgresqlDatabase=movies \
bitnami/postgresql -f values.yaml
Loading

0 comments on commit 0cf16cb

Please sign in to comment.