Skip to content

gRPC example #2284

Closed
Closed
@pcj

Description

@pcj

Related to #39 & #2207, I'm psyched to try #2223 + #2246. However, I'm hoping we can use this issue to define an example set of yaml files to use this new feature. I've posted my current set of nginx-ingress config files and hoping to get clarification best practices for gRPC use. I've left out the rbac.yaml file as I assume that does not need any changes.

# nginx-ingress-controller.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
        k8s-app: nginx-ingress-lb
  template:
    metadata:
      annotations:
        prometheus.io/scrape: 'true'
        prometheus.io/port: '10254'
      labels:
        k8s-app: nginx-ingress-lb
    spec:
      serviceAccountName: nginx-ingress-serviceaccount
      containers:
        - name: nginx-ingress-controller
          image: gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.15
          args:
             - /nginx-ingress-controller
             - --default-backend-service=default/default-http-backend
             - --default-ssl-certificate=$(POD_NAMESPACE)/tls-certificate
          env:
             - name: POD_NAME
               valueFrom:
                 fieldRef:
                   fieldPath: metadata.name
             - name: POD_NAMESPACE
               valueFrom:
                 fieldRef:
                   fieldPath: metadata.namespace
          ports:
          - name: http
            containerPort: 80
          - name: https
            containerPort: 443
# nginx-ingress-controller-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-ingress
  namespace: default
spec:
  type: LoadBalancer
  ports:
  ports:
  - name: http
    port: 80
    targetPort: http
  - name: https
    port: 443
    targetPort: https
  selector:
    k8s-app: nginx-ingress-lb
# ingress-default-backend.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: default-http-backend
  labels:
    k8s-app: default-http-backend
  namespace: default
spec:
  replicas: 1
  template:
    metadata:
      labels:
        k8s-app: default-http-backend
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name: default-http-backend
        # Any image is permissable as long as:
        # 1. It serves a 404 page at /
        # 2. It serves 200 on a /healthz endpoint
        image: gcr.io/google_containers/defaultbackend:1.0
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 30
          timeoutSeconds: 5
        ports:
        - containerPort: 8080
        resources:
          limits:
            cpu: 10m
            memory: 20Mi
          requests:
            cpu: 10m
            memory: 20Mi
---
apiVersion: v1
kind: Service
metadata:
  name: default-http-backend
  namespace: default
  labels:
    k8s-app: default-http-backend
spec:
  ports:
  - port: 80
    targetPort: 8080
  selector:
    k8s-app: default-http-backend

I have a gRPC service defined as follows. dam-app is an insecure gRPC server listening on TCP port 5151. For simplicity, I'm looking to expose 5151 externally that routes grpc traffic 5151:5151 to the service / deployment. I'm using kube-cert-manager for dynamic letsencrypt certificates and would like to terminate TLS at the nginx-ingress level and run insecure grpc services internally (perhaps I should terminate TLS in the POD? Not sure I need that).

# grpc-deploy.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: dam-app
  labels:
    k8s-app: dam-app
  namespace: default
spec:
  replicas: 1
  template:
    metadata:
      labels:
        k8s-app: dam-app
    spec:
      containers:
      - name: dam-app
        image: gcr.io/foo-bar-baz/dam-app:dev
        ports:
        - containerPort: 5151
# grpc-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: dam-service
  namespace: default
  labels:
    k8s-app: dam-app
spec:
  ports:
  - port: 5151
    targetPort: 5151
    name: grpc
  selector:
    k8s-app: dam-app
# grpc-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "nginx"
    ingress.kubernetes.io/ssl-redirect: "true"
  name: dam-ingress
  namespace: default
spec:
  rules:
  - host: grpc.example.com
    http:
      paths:
      - backend:
          serviceName: dam-service
          servicePort: 5151
  tls:
  - secretName: grpc.example.com
    hosts:
      - grpc.example.com

Based on PR #2223, looks like all I need to do is:

  1. Replace gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.15 with quay.io/aledbf/nginx-ingress-controller:0.348.
  2. Add the annotation nginx.ingress.kubernetes.io/grpc-backend: "true" to my gprc-ingress.yaml.

Is that it?

Is a fancier default backend needed?

(any suggestions on tuning up these yaml files also welcome)

One more thing, what is going to be the recommended image going forward?

Thanks for all your work @aledbf and others on this feature!

Edit: changed 0.345 to 0.348 as this is the newest image at https://quay.io/repository/aledbf/nginx-ingress-controller?tab=tags

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/documentationCategorizes issue or PR as related to documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions