Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for TCP/UDP load balancing via stream-snippets configmap key #340

Merged
merged 1 commit into from
Aug 17, 2018

Conversation

pleshakov
Copy link
Contributor

Proposed changes

This PR introduces two ConfigMap keys:

  • stream-snippets, which sets a custom snippet in stream context.
  • stream-log-format, which sets a custom log format for TCP/UDP load balancing in stream context.

With stream-snippets it is possible to support TCP or UPD load balancing:

For NGINX OSS:

kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config
  namespace: nginx-ingress
data:
    stream-snippets: |
      upstream tcp-coffee {
          server coffee-svc.default.svc.cluster.local:80;
      }

      server {
          listen 4455;
          proxy_pass tcp-coffee;
      }

      upstream tcp-tea {
          server tea-svc.default.svc.cluster.local:80;
      }

      server {
          listen 4456;
          proxy_pass tcp-tea;
      }

Notes for NGINX:

  • If a DNS name such as coffee-svc.default.svc.cluster.local cannot be resolved, NGINX will fail to reload
  • NGINX resolves a DNS name only once. The next time the name will be resolved is during the next config reload.

For NGINX Plus:

kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config
  namespace: nginx-ingress
data:
    stream-snippets: |
      resolver kube-dns.kube-system.svc.cluster.local valid=5s;

      upstream tcp-coffee {
          zone tcp-coffee 64k;
          server coffee-svc.default.svc.cluster.local service=_http._tcp resolve;
      }

      server {
          listen 4455;
          proxy_pass tcp-coffee;
          status_zone coffee-stream;
      }

      upstream tcp-tea {
          zone tcp-tea 64k;
          server tea-svc.default.svc.cluster.local service=_http._tcp resolve;
      }

      server {
          listen 4456;
          proxy_pass tcp-tea;
          status_zone tea-stream;
      }

Notes for NGINX Plus:

To apply the ConfigMap run:

$ kubectl apply -f nginx-config.yaml

You can also check if the config was applied successfully:

$  kubectl describe configmap nginx-config -n nginx-ingress
. . .
Events:
  Type    Reason   Age                From                      Message
  ----    ------   ----               ----                      -------
  Normal  Updated  17s (x2 over 28s)  nginx-ingress-controller  Configuration from nginx-ingress/nginx-config was updated

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto master
  • I will ensure my PR is targeting the master branch and pulling from my branch from my own fork

Copy link
Contributor

@isaachawley isaachawley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, works in GKE. One question then I'll approve.

@@ -108,3 +108,19 @@ http {

include /etc/nginx/conf.d/*.conf;
}

stream {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stream block will appear even if there are no stream snippets - is that required?

Copy link
Contributor

@isaachawley isaachawley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
server {
listen 4456;
proxy_pass tcp-tea;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upstream is called tcp-coffee in this case. Also, I would choose different port than 80 when giving example for streams :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. thank you!

- Add stream-snippets configmap key
- Add stream-log-format configmap key
@pleshakov pleshakov merged commit ef84a56 into master Aug 17, 2018
@pleshakov pleshakov deleted the tcp-udp-workaround branch August 17, 2018 10:24
@pleshakov pleshakov added the enhancement Pull requests for new features/feature enhancements label Aug 20, 2018
@pleshakov pleshakov mentioned this pull request Aug 21, 2018
@pleshakov pleshakov changed the title Support for TCP/UDP load balancing via stream-snippets Support for TCP/UDP load balancing via stream-snippets configmap key Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Pull requests for new features/feature enhancements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants