Skip to content

Instantly share code, notes, and snippets.

@stanislavhordiyenko
Last active September 8, 2021 11:33
Show Gist options
  • Save stanislavhordiyenko/e2e0886892faf7c3a072454bfd3814ad to your computer and use it in GitHub Desktop.
Save stanislavhordiyenko/e2e0886892faf7c3a072454bfd3814ad to your computer and use it in GitHub Desktop.
gcp-default-ingress-and-traefik
  1. Make sure that Traefik service is installed as a NodeGroup (it can be done with Helm);
  2. Create global static ip address in GCP (i.e. my-static-ip);
  3. Deploy default ingress with kubectl command:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: catch-all-ingress
  # Namespace where the Traefik is running
  namespace: traefik
  annotations:
    # Name should be the same as in step #2
    kubernetes.io/ingress.global-static-ip-name: "my-static-ip"
    kubernetes.io/ingress.class: "gce"
spec:
  defaultBackend:
    service:
      name: traefik
      port:
        name: web
  1. Deploy test application with kubectl command:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  namespace: default
spec:
  selector:
    matchLabels:
      run: web
  template:
    metadata:
      labels:
        run: web
    spec:
      containers:
      - image: gcr.io/google-samples/hello-app:2.0
        imagePullPolicy: IfNotPresent
        name: web
        ports:
        - containerPort: 8080
          protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  name: web
  namespace: default
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    run: web
  type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
  rules:
  - host: your.domain.com
    http:
      paths:
      - path: /*
        pathType: ImplementationSpecific
        backend:
          service:
            name: web
            port:
              number: 80
---
# This default Traefik ingress is created for health checks. Without it load balancer cannot talk to Traefik
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-default-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/router.entrypoints: web
spec:
  defaultBackend:
    service:
      name: web
      port:
        number: 80
  1. Create A DNS record with your.domain.com domain and point to ip address that is created in step #2;
  2. Navigate to http://your.domain.com/ and a simple web application will be displayed.

Now, Cloud Armor can be assigned to the default load balancer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment