Git Product home page Git Product logo

cloudflare-gke's Introduction

Cloudflare x GKE - Proof of Concepts

Some proof-of-concepts that demonstrate how Cloudflare can work with GKE.

Getting started

Step 0: Prerequisites:

Step 1: Bootstrap the GKE environment with Terraform

1.1 Initialize Terraform terraform init

1.2 Plan Terraform and verify the plan terraform plan

(Optional) Set the variables as environment variables if you want want to entering them interactively every time you plan. For example,

# Read from the local user name
export TF_VAR_resource_prefix=$USER
# Read from gcloud default project id
export TF_VAR_gcp_project_id=$(gcloud config get-value project)

1.3 Apply the Terraform plan

terraform apply

It will takes > 10 minutes.

Step 2: Deploy your workloads to to the GKE environment with kubectl

2.1 Connect to the cluster Follow the instructions in GCP Console -> Kubernetes Engine -> Cluster -> Connect OR run

gcloud container clusters get-credentials <CLUSTER_NAME>

2.2 Run some kubectl to make sure it's configured correctly. kubectl config get-contexts

2.3 The foundation has been laid. The real fun starts from here...

Deployment Mode 1: Cloudflare Argo Tunnel in Sidecar Model with Cloudflare Load Balancer

cloudflared-sidecar.yaml

Architecture

cloudflared-sidecar

Integration with Cloudflare

  1. Login in to Cloudflare Argo Tunnel

cloudflared tunnel login

  1. Load the cert to the K8s secret store

kubectl create secret generic cloudflared-cert --from-file="$HOME/.cloudflared/cert.pem"

  1. Apply the deployment

kubectl apply -f cloudflared-sidecar.yaml

  1. Check Cloudflare dashboard > Traffic > Argo Tunnel

References

OOMKill Exit Code 137

Solution: remove resource limit My Container is terminated

Deployment Mode 2: Cloudflare with GKE Ingress with GKE External Load Balancer

gke-ingress.yaml

Architecture:

gke-ingress

Integration with Cloudflare

  1. Apply the deployment

kubectl apply -f gke-ingress.yaml

  1. Get the external IP address

kubectl get ingress

  1. Add it to Cloudflare DNS as an origin

References

Error 400 when creating ingress

Error during sync: error running load balancer syncing routine: loadbalancer default-cwang-httpbin-ingress--6029373544ea4799 does not exist: googleapi: Error 400: STANDARD network tier (the project's default network tier) is not supported: STANDARD network tier is not supported for global forwarding rule., badRequest

Just set the Network Service Tier to Premium. Using Network Service Tiers

Deployment Mode 3: Cloudflare Argo Tunnel in "Trailer" mode without Cloudflare Load Balancer or GCP Forwarding Rule

cloudflared-trailer.yaml

Architecture:

cloudflared-trailer

Integration with Cloudflare

  1. Login in to Cloudflare Argo Tunnel

cloudflared tunnel login

  1. Load the cert to the K8s secret store

kubectl create secret generic cloudflared-cert --from-file="$HOME/.cloudflared/cert.pem"

  1. Apply the deployment

kubectl apply -f cloudflared-trailer.yaml

  1. Check Cloudflare dashboard > Traffic > Argo Tunnel

Error - cloudflared listening to service

The service is not working.

kubectl run -it --rm --restart=Never alpine --image=alpine sh

If you don't see a command prompt, try pressing enter.
/ # wget -O- cwang-gke-int-lb-service
Connecting to cwang-gke-int-lb-service (10.112.9.183:80)
wget: can't connect to remote host (10.112.9.183): Connection refused

Service is not associated with the correct deployment?

kubectl describe  endpoints cwang-gke-int-lb-service
Name:         cwang-gke-int-lb-service
Namespace:    default
Labels:       app=cwang-gke-int-lb-app
Annotations:  <none>
Subsets:
Events:  <none>

References

Misc

Google Cloud

GKE and Kubernetes

Terraform

kubectl Cheatsheet

kubectl config current-context 
kubectl create -f FILE.yaml
kubectl apply -f FILE.yaml
kubectl delete -f FILE.yaml
kubectl get namespace
kubectl config get-contexts  
kubectl get po --output wide
kubectl describe pods
kubectl logs POD_NAME CONTAINER_NAME
kubectl top node
kubectl get ingress INGRESS_NAME --output yaml
kubectl exec POD_NAME   -- printenv | grep SERVICE   
kubectl exec -it POD_NAME -- /bin/bash
kubectl run -it --rm --restart=Never alpine --image=alpine sh
kubectl get endpoints
kubectl scale deploy tunnel --replicas=2

terraform Cheatsheet

terraform show gke.tf

cloudflare-gke's People

Contributors

mw866 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

cloudflare-gke's Issues

No Address for load balancer: missing step of creating static ip in deploy mode 2

According to the Readme, users should get the address for passing to CF DNS here.

$ kubectl get ingress gke-ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
gke-ingress * 80 58s

However, there is no address.

Following the instructions here, it appears that the creation of the static IP must be done independently prior to the kubectl apply.

gcloud compute addresses create gke-ingress-static-ip --global

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.