Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

Commit

Permalink
Rename project to appmesh-gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Nov 1, 2019
1 parent 66d7ac9 commit df02398
Show file tree
Hide file tree
Showing 43 changed files with 204 additions and 287 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ jobs:
uses: stefanprodan/kube-tools@v1
with:
command: |
echo "build gateways"
kustomize build ./kustomize/ns-gateway | kubeval --strict --ignore-missing-schemas
kustomize build ./kustomize/envoy-gateway | kubeval --strict --ignore-missing-schemas
echo "build gateway"
kustomize build ./kustomize/appmesh-gateway | kubeval --strict --ignore-missing-schemas
echo "build podinfo"
kustomize build ./kustomize/podinfo | kubeval --strict --ignore-missing-schemas
echo "build tester"
kustomize build ./kustomize/tester | kubeval --strict --ignore-missing-schemas
echo "build test"
kustomize build ./kustomize/test | kubeval --strict --ignore-missing-schemas
build:
runs-on: ubuntu-latest
needs: [kustomize]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
run: |
if [[ "${GITHUB_REF}" == "refs/tags"* ]]; then
DOCKER_TAG=$(echo ${GITHUB_REF} | rev | cut -d/ -f1 | rev)
docker build . -t ${{ secrets.DOCKER_USERNAME }}/kxds:${DOCKER_TAG}
docker push ${{ secrets.DOCKER_USERNAME }}/kxds:${DOCKER_TAG}
docker build . -t ${{ secrets.DOCKER_USERNAME }}/appmesh-gateway:${DOCKER_TAG}
docker push ${{ secrets.DOCKER_USERNAME }}/appmesh-gateway:${DOCKER_TAG}
fi
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM golang:1.13 as builder

RUN mkdir -p /kxds/
RUN mkdir -p /appmesh-gateway/

WORKDIR /kxds
WORKDIR /appmesh-gateway

COPY . .

RUN go mod download

RUN go test -v -race ./...

RUN CGO_ENABLED=0 GOOS=linux go build -a -o bin/kxds cmd/kxds/*
RUN CGO_ENABLED=0 GOOS=linux go build -a -o bin/appmesh-gateway cmd/appmesh-gateway/*

FROM alpine:3.10

Expand All @@ -21,9 +21,9 @@ RUN addgroup -S app \

WORKDIR /home/app

COPY --from=builder /kxds/bin/kxds .
COPY --from=builder /appmesh-gateway/bin/appmesh-gateway .
RUN chown -R app:app ./

USER app

CMD ["./kxds"]
CMD ["./appmesh-gateway"]
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
TAG?=latest
VERSION?=$(shell grep 'VERSION' cmd/kxds/main.go | awk '{ print $$4 }' | tr -d '"' | head -n1)
NAME:=kxds
VERSION?=$(shell grep 'VERSION' cmd/appmesh-gateway/main.go | awk '{ print $$4 }' | tr -d '"' | head -n1)
NAME:=appmesh-gateway
DOCKER_REPOSITORY:=stefanprodan
DOCKER_IMAGE_NAME:=$(DOCKER_REPOSITORY)/$(NAME)

build:
go build -o bin/kxds cmd/kxds/*.go
go build -o bin/appmesh-gateway cmd/appmesh-gateway/*.go

test:
go test -v -race ./...

run:
go run cmd/kxds/*.go kubernetes --kubeconfig=$$HOME/.kube/config \
go run cmd/appmesh-gateway/*.go kubernetes --kubeconfig=$$HOME/.kube/config \
--port-name=http

appmesh:
go run cmd/kxds/*.go appmesh --kubeconfig=$$HOME/.kube/config \
go run cmd/appmesh-gateway/*.go appmesh --kubeconfig=$$HOME/.kube/config \
--gateway-mesh=appmesh --gateway-name=gateway --gateway-namespace=appmesh-gateway

envoy:
envoy -c envoy.yaml -l info

build-container:
docker build -t $(DOCKER_IMAGE_NAME):$(VERSION) .
docker build -t $(DOCKER_IMAGE_NAME):v$(VERSION) .

push-container: build-container
docker push $(DOCKER_IMAGE_NAME):$(VERSION)
docker push $(DOCKER_IMAGE_NAME):v$(VERSION)

version-set:
@next="$(TAG)" && \
current="$(VERSION)" && \
sed -i '' "s/$$current/$$next/g" cmd/kxds/main.go && \
sed -i '' "s/kxds:v$$current/kxds:v$$next/g" kustomize/base/gateway/deployment.yaml && \
sed -i '' "s/$$current/$$next/g" cmd/appmesh-gateway/main.go && \
sed -i '' "s/appmesh-gateway:v$$current/appmesh-gateway:v$$next/g" kustomize/base/appmesh-gateway/deployment.yaml && \
echo "Version $$next set in code and kustomization"
110 changes: 35 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,63 @@
# KxDS
[![CI](https://github.com/stefanprodan/kxds/workflows/CI/badge.svg)](https://github.com/stefanprodan/kxds/actions)
[![report](https://goreportcard.com/badge/github.com/stefanprodan/kxds)](https://goreportcard.com/report/github.com/stefanprodan/kxds)
# appmesh-gateway
[![CI](https://github.com/stefanprodan/appmesh-gateway/workflows/CI/badge.svg)](https://github.com/stefanprodan/appmesh-gateway/actions)
[![report](https://goreportcard.com/badge/github.com/stefanprodan/appmesh-gateway)](https://goreportcard.com/report/github.com/stefanprodan/appmesh-gateway)

KxDS is an [Envoy](https://www.envoyproxy.io/) discovery service implementation for Kubernetes.
It runs as a sidecar next to Envoy and configures the proxy to expose Kubernetes services.
App Mesh Gateway is an edge load balancer that exposes applications outside the mesh.

### Features
The gateway is composed of:
* [Envoy](https://www.envoyproxy.io/) proxy
* Envoy data plane API (CDS/RDS/LDS)
* Kubernetes controller

* **Kubernetes Service Discovery** KxDS watches Kubernetes for services with a `http` named port
* **App Mesh Service Discovery** KxDS watches Kubernetes for App Mesh virtual services
* **Envoy Clusters (CDS)** are generated for each Kubernetes service or App Mesh virtual services
* **Envoy Routes (RDS)** are generated for each cluster and configured with timeouts and retry policies
* **Envoy Weighted Clusters** are generated based on Kubernetes service annotations
* **Envoy Listeners (LDS)** KxDS configures Envoy to listen on port `8080`
An App Mesh virtual service can be exposed outside the mesh by annotating the object with:

### Internal Kubernetes Gateway

Install the API Gateway as NodePort scoped to a namespace:

```sh
kubectl create ns test
kubectl -n test apply -k github.com/stefanprodan/kxds//kustomize/ns-gateway
```yaml
apiVersion: appmesh.k8s.aws/v1beta1
kind: VirtualService
metadata:
name: frontend.test
annotations:
gateway.appmesh.k8s.aws/expose: "true"
gateway.appmesh.k8s.aws/domain: "frontend.example.com"
```
The above gateway will expose all Kubernetes services in the test namespace that have a `http` named port.

Deploy podinfo in the `test` namespace:

If you want to expose the service inside the Kubernetes cluster you can omit the domain annotation.
By default the gateway exposes a virtual service by its name,
a service can be accessed by setting the host HTTP header e.g.:
```sh
kubectl -n test apply -k github.com/stefanprodan/kxds//kustomize/podinfo
curl -H 'Host: frontend.test' http://<gateway-host>/
```
Port forward to the gateway:
The gateway registers/de-registers virtual services automatically as they come and go in the cluster.
```sh
kubectl -n test port-forward svc/gateway 8080:80
```
### Install
Access the podinfo API by setting the host header to `podinfo.test`:
Install the API Gateway as NLB in `appmesh-gateway` namespace:

```sh
curl -vH 'Host: podinfo.test' localhost:8080
kubectl apply -k github.com/stefanprodan/appmesh-gateway//kustomize/appmesh-gateway
```

### External Kubernetes Gateway

Install the API Gateway as LoadBalancer in `envoy-gateway` namespace:
Deploy podinfo in the `test` namespace:

```sh
kubectl apply -k github.com/stefanprodan/kxds//kustomize/envoy-gateway
kubectl -n test apply -k github.com/stefanprodan/appmesh-gateway//kustomize/test
```

The above gateway will expose all Kubernetes services in the cluster that have a `http` named port.

### Annotations
Port forward to the gateway:

Kubernetes service exposed on an external domain:
```yaml
apiVersion: v1
kind: Service
metadata:
name: frontend
namespace: demo
annotations:
envoy.gateway.kubernetes.io/expose: "true"
envoy.gateway.kubernetes.io/timeout: "25s"
envoy.gateway.kubernetes.io/retries: "5"
envoy.gateway.kubernetes.io/domain: "frontend.example.com"
spec:
ports:
- name: http
port: 9898
protocol: TCP
```sh
kubectl -n appmesh-gateway port-forward svc/appmesh-gateway 8080:80
```

Traffic split with weighted destinations:
Access the podinfo API by setting the host header to `podinfo.test`:

```yaml
apiVersion: v1
kind: Service
metadata:
name: backend
namespace: demo
annotations:
envoy.gateway.kubernetes.io/domain: "backend.demo"
envoy.gateway.kubernetes.io/primary: "backend-primary-demo-9898"
envoy.gateway.kubernetes.io/canary: "backend-canary-demo-9898"
envoy.gateway.kubernetes.io/canary-weight: "50"
```sh
curl -vH 'Host: podinfo.test' localhost:8080
```

The primary and canary name format is `<service-name>-<namespace>-<port>`.
Note that both Kubernetes services must exist or Envoy will reject the configuration.

### App Mesh Gateway

Install the API Gateway as NLB in `appmesh-gateway` namespace:
Access podinfo on its custom domain:

```sh
kubectl apply -k github.com/stefanprodan/kxds//kustomize/envoy-gateway
curl -vH 'Host: podinfo.internal' localhost:8080
```

The above gateway will expose all App Mesh virtual services in the cluster.
8 changes: 4 additions & 4 deletions cmd/kxds/appmesh.go → cmd/appmesh-gateway/appmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"

"github.com/stefanprodan/kxds/pkg/discovery"
"github.com/stefanprodan/kxds/pkg/envoy"
"github.com/stefanprodan/kxds/pkg/server"
"github.com/stefanprodan/kxds/pkg/signals"
"github.com/stefanprodan/appmesh-gateway/pkg/discovery"
"github.com/stefanprodan/appmesh-gateway/pkg/envoy"
"github.com/stefanprodan/appmesh-gateway/pkg/server"
"github.com/stefanprodan/appmesh-gateway/pkg/signals"
)

var gatewayMesh string
Expand Down
8 changes: 4 additions & 4 deletions cmd/kxds/kubernetes.go → cmd/appmesh-gateway/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"

"github.com/stefanprodan/kxds/pkg/discovery"
"github.com/stefanprodan/kxds/pkg/envoy"
"github.com/stefanprodan/kxds/pkg/server"
"github.com/stefanprodan/kxds/pkg/signals"
"github.com/stefanprodan/appmesh-gateway/pkg/discovery"
"github.com/stefanprodan/appmesh-gateway/pkg/envoy"
"github.com/stefanprodan/appmesh-gateway/pkg/server"
"github.com/stefanprodan/appmesh-gateway/pkg/signals"
)

var portName string
Expand Down
2 changes: 1 addition & 1 deletion cmd/kxds/main.go → cmd/appmesh-gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra"
)

const VERSION = "0.2.0"
const VERSION = "0.3.0"

var (
masterURL string
Expand Down
4 changes: 2 additions & 2 deletions envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ admin:
address:
socket_address:
address: 0.0.0.0
port_value: 9000
port_value: 8081

dynamic_resources:
ads_config:
Expand All @@ -23,7 +23,7 @@ dynamic_resources:
static_resources:
clusters:
- name: xds
connect_timeout: 0.30s
connect_timeout: 0.50s
type: static
http2_protocol_options: {}
load_assignment:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/stefanprodan/kxds
module github.com/stefanprodan/appmesh-gateway

go 1.13

Expand Down
6 changes: 3 additions & 3 deletions kustomize/appmesh-gateway/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: gateway
name: appmesh-gateway
spec:
template:
metadata:
Expand All @@ -12,9 +12,9 @@ spec:
appmesh.k8s.aws/egressIgnoredPorts: "18000,22,443"
spec:
containers:
- name: kxds
- name: gateway
command:
- ./kxds
- ./appmesh-gateway
- appmesh
- --port=18000
- --gateway-mesh=appmesh
Expand Down
3 changes: 1 addition & 2 deletions kustomize/appmesh-gateway/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: appmesh-gateway
namePrefix: appmesh-
bases:
- ../base/gateway
- ../base/appmesh-gateway
resources:
- namespace.yaml
- rbac.yaml
Expand Down
2 changes: 0 additions & 2 deletions kustomize/appmesh-gateway/namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ apiVersion: v1
kind: Namespace
metadata:
name: appmesh-gateway
annotations:
fluxcd.io/ignore: "false"
labels:
appmesh.k8s.aws/sidecarInjectorWebhook: enabled
8 changes: 4 additions & 4 deletions kustomize/appmesh-gateway/rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: gateway
name: appmesh-gateway
rules:
- apiGroups:
- ""
Expand All @@ -22,12 +22,12 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: gateway
name: appmesh-gateway
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: gateway
name: appmesh-gateway
subjects:
- kind: ServiceAccount
name: gateway
name: appmesh-gateway
namespace: appmesh-gateway
2 changes: 1 addition & 1 deletion kustomize/appmesh-gateway/service.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: Service
metadata:
name: gateway
name: appmesh-gateway
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
spec:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: gateway
name: appmesh-gateway
Loading

0 comments on commit df02398

Please sign in to comment.