/k8s-gateway-api

An example how to use gateway api in GKE

Primary LanguageHCLGNU General Public License v3.0GPL-3.0

k8s-gateway-api

CodeQL tfsec

This repository is an example to use gateway api in GKE. If you want yo read more about it:

In a nutshell Gateway API is an open source that was created by the SIG-NETWORK community. The gateway API bring some resources that interact with Kubernetes service networking through expressive, extensible, and role-oriented interfaces.

Gateway API Structure

Foo

GKE Gateway API Resources

Foo

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project.

Prerequisites

  • git
  • make
  • python
  • pip
  • virtualenv
  • vscode
  • terraform
  • skaffold
  • docker
  • minikube
  • kubectl
  • kubectx
  • gcloud

To deloy this project you will need a Google Cloud account, create here.

Costs

This tutorial uses the following billable components of Google Cloud:

To generate a cost estimate based on your projected usage, use the pricing calculator.

When you finish this tutorial, you can avoid continued billing by deleting the resources you created. For more information, see Clean up.

Deploying

First of all you need to clone this repository:

git clone https://github.com/claick-oliveira/k8s-gateway-api

To deploy this project we use terraform, but if you prefer you can see the commands to create the infrastrcutre in COMMANDS.

Infrastructure

First let's check the architecture that we will create.

#TODO: ## Add the architecture diagram

Terraform

Now that we know about the architecture and resources, let's create. First we need to connect our shell to the gcloud:

gcloud auth login

Now that we connected:

cd terraform
terraform apply

This project you need to fill some variables:

  • gcp_project_name: The GCP project ID
  • gcp_region: The GCP region
  • gcp_zone: The GCP availability zone

Running the service

First we need to connect in our GKE:

gcloud container clusters get-credentials <CLUSTER_NAME> --region <REGION> --project <PROJECT_ID>

To be easy and skaffold use the correct environment, let's configure kubectx:

Get the name of the environment:

kubectx

Now change the name for staging:

kubectx gateway-api=<YOUR ENVIRONMENT>

Let's create the gateway:

kubectl apply  -f kubernetes/gateway.yaml

Now you need to create the http-route file based on the file http-route.yaml.template and change the variable <YOUR DOMAIN>.

To run the server you need to execute, but you need to be in the root folder:

skaffold run --default-repo us-central1-docker.pkg.dev/<PROJECT_ID>/gateway-api

To request the application, first we need to get the loadbalancer's IP:

kubectl get gateway

Get the ADDRESS.With the IP we can request:

curl -H "host: <YOUR DOMAIN>" <YOUR IP>/health

The answer will be:

{"status":"up"}

Application

Access the folder and create your virtual env:

cd k8s-gateway-api
make venv

Now let's activate your virtual env:

make activate

To start to code you need to install the requirements and de dev requirements:

make requirements
make requirementsdev

Running the tests

To run the tests you need to execute:

make test

And coding style tests

In this project we'll use PEP 8 as style guide.

Clean

To clean the files generated as coverage, builds, env you can use:

make cleanfull
skaffold delete

To clean the infrastructure:

terraform destroy

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the GNU General Public License - see the LICENSE file for details