Deploying Kubernetes cluster with KGateway on AWS for beginners
In this blog, we will quickly go through how can we deploy our application on AWS EKS cluster with kgateway.
We will go through following things -
Installing Gateway Crd’s
Deploying a FooBar test application
Exposing endpoints via KGateway
Accessing our services externally
If you don’t know how to create an eks cluster this video might help you out -
Install Gateway API CRD’s →
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.3.0/standard-install.yaml
Check if resources have installed →
kubectl api-resources --api-group=gateway.networking.k8s.io
You should get following output →
NAME SHORTNAMES APIGROUP NAMESPACED KIND
gatewayclasses gc gateway.networking.k8s.io false GatewayClass
gateways gtw gateway.networking.k8s.io true Gateway
grpcroutes gateway.networking.k8s.io true GRPCRoute
httproutes gateway.networking.k8s.io true HTTPRoute
referencegrants refgrant gateway.networking.k8s.io true ReferenceGrant
Install helm →
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
Deploy the kgateway CRDs by using Helm →
helm upgrade -i --create-namespace --namespace kgateway-system --version v2.0.4 kgateway-crds oci://cr.kgateway.dev/kgateway-dev/charts/kgateway-crds
Install the kgateway CRDs using Helm →
helm upgrade -i --namespace kgateway-system --version v2.0.4 kgateway oci://cr.kgateway.dev/kgateway-dev/charts/kgateway
Now your gateway is up and running. Now to check if is working →
kubectl get pods -n kgateway-system
output →
NAME READY STATUS RESTARTS AGE
kgateway-7dcc5fbf9-cdqwh 1/1 Running 0 14s
Now lets deploy our test application.
Below we are setting up our fooBar application, in there we have 2 pods. 1 of foo server that has route /foo and return foo-app and 2nd one is bar server that has route /bar and returns bar-app.
copy paste this in the terminal to spin up pods and services →
cat <<EOF | kubectl apply -f -
kind: Pod
apiVersion: v1
metadata:
name: foo-app
labels:
app: foo
spec:
containers:
- command:
- /agnhost
- serve-hostname
- --http=true
- --port=8080
image: registry.k8s.io/e2e-test-images/agnhost:2.39
name: foo-app
---
kind: Service
apiVersion: v1
metadata:
name: foo-service
spec:
selector:
app: foo
ports:
- port: 8080
---
kind: Pod
apiVersion: v1
metadata:
name: bar-app
labels:
app: bar
spec:
containers:
- command:
- /agnhost
- serve-hostname
- --http=true
- --port=8080
image: registry.k8s.io/e2e-test-images/agnhost:2.39
name: bar-app
---
kind: Service
apiVersion: v1
metadata:
name: bar-service
spec:
selector:
app: bar
ports:
- port: 8080
---
EOF
pod/foo-app created
service/foo-service created
pod/bar-app created
service/bar-service created
Now let’s set up our gateway. This will create a gateway with name my-gateway on port 80 →
cat <<EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: my-gateway
spec:
gatewayClassName: kgateway
listeners:
- name: http
port: 80
protocol: HTTP
EOF
But wait we did not specify where should the request to our applications route to. How will it route proper then?
For that we need to set up a httpRouter that will be connected to our gateway and route the requests to appropriate pods.
cat <<EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: hello
spec:
parentRefs:
- name: my-gateway
# hostnames:
# - "hello.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /foo
backendRefs:
- name: foo-service
port: 8080
- matches:
- path:
type: PathPrefix
value: /bar
backendRefs:
- name: bar-service
port: 8080
EOF
Now our application has been completely deployed
kubectl get gateway
this will give us the gateway that we just setup
NAME CLASS ADDRESS PROGRAMMED AGE
my-gateway kgateway a869d3b6146174ac4aae7a37404f3edf-991812074.ap-south-1.elb.amazonaws.com True 33s
now as you can see our gateway has been set up and has an address a869d3b6146174ac4aae7a37404f3edf-991812074.ap-south-1.elb.amazonaws.com and we can access our application at this address.
kgatewaybasic % curl a869d3b6146174ac4aae7a37404f3edf-991812074.ap-south-1.elb.amazonaws.com/foo
foo-app
kgatewaybasic % curl a869d3b6146174ac4aae7a37404f3edf-991812074.ap-south-1.elb.amazonaws.com/bar
bar-app
