Skip to content

Instantly share code, notes, and snippets.

@chukaofili
Last active October 19, 2021 01:29
Show Gist options
  • Save chukaofili/d0a6713734d0953ce1ce667958464edb to your computer and use it in GitHub Desktop.
Save chukaofili/d0a6713734d0953ce1ce667958464edb to your computer and use it in GitHub Desktop.
Echo Server Deployment
apiVersion: v1
kind: Namespace
metadata:
name: echoserver
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: echoserver
namespace: echoserver
spec:
replicas: 3
template:
metadata:
labels:
app: echoserver
spec:
containers:
- image: gcr.io/google_containers/echoserver:1.0
imagePullPolicy: Always
name: echoserver
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: echoserver
namespace: echoserver
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
selector:
app: echoserver
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: echoserver
namespace: echoserver
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: echo.example.com
http:
paths:
- path: /
backend:
serviceName: echoserver
servicePort: 80
@roock
Copy link

roock commented Oct 14, 2019

Doesn't work with Kubernetes 1.16+. see https://gist.github.com/roock/26e915450dfcac2a70ed6e44e0c75cde for a working version with Kubernetes 1.16

@ivanovUA
Copy link

ivanovUA commented Aug 7, 2020

Need to change
apiVersion: extensions/v1beta1
to
apiVersion: apps/v1

apiVersion: apps/v1
kind: Deployment
metadata:
  name: echoserver
spec:
  replicas: 3
  selector:
    matchLabels:
      app: echoserver
  template:
    metadata:
      labels:
        app: echoserver
    spec:
      containers:
      - image: gcr.io/google_containers/echoserver:1.0
        imagePullPolicy: Always
        name: echoserver
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: echoserver
spec:
  ports:
  - port: 80
    targetPort: 8080
    protocol: TCP
  selector:
    app: echoserver
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: echoserver
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: echo.example.com
    http:
      paths:
      - path: /
        backend:
          serviceName: echoserver
          servicePort: 80

@chukaofili
Copy link
Author

chukaofili commented Aug 7, 2020

@roock @ivanovUA Thanks, updated

@ameir
Copy link

ameir commented Feb 25, 2021

FYI, I also had to add

  selector:
    matchLabels:
      app: echoserver

on a Kubernetes 1.18 cluster.

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