Skip to content

Instantly share code, notes, and snippets.

@ram-nadella
Last active August 4, 2019 00:18
Show Gist options
  • Save ram-nadella/778b06acaf468c83deaac329ba5d185c to your computer and use it in GitHub Desktop.
Save ram-nadella/778b06acaf468c83deaac329ba5d185c to your computer and use it in GitHub Desktop.
GKE nginx ingress example
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-server
spec:
replicas: 2
selector:
matchLabels:
app: hello-server-app
template:
metadata:
labels:
app: hello-server-app
spec:
containers:
- name: hello-server
image: gcr.io/google-samples/hello-app:1.0
ports:
- containerPort: 8080
env:
- name: PORT
value: "8080"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-plain-text
spec:
replicas: 2
selector:
matchLabels:
app: hello-plain-text
template:
metadata:
labels:
app: hello-plain-text
spec:
containers:
- name: hello-plain-text
image: nginxdemos/hello:plain-text
ports:
- containerPort: 80

Basic nginx ingress + LB (auto-provisioned & managed by GKE) routing example

Place yaml files in a dir and run kubectl apply -f .

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: p8-ingress-nginx
annotations:
# use the shared ingress-nginx
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: hello-server
servicePort: 8081
- path: /plain/[A-Z0-9]{3}/abc
backend:
serviceName: hello-plain-text
servicePort: 80
apiVersion: v1
kind: Service
metadata:
name: hello-server
spec:
selector:
app: hello-server-app
ports:
- port: 8081
targetPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: hello-plain-text
spec:
selector:
app: hello-plain-text
ports:
- port: 80
targetPort: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment