Skip to content

Instantly share code, notes, and snippets.

@suside
Created April 20, 2017 12:08
Show Gist options
  • Select an option

  • Save suside/d80403137550f9a8f2948071edefa059 to your computer and use it in GitHub Desktop.

Select an option

Save suside/d80403137550f9a8f2948071edefa059 to your computer and use it in GitHub Desktop.

Revisions

  1. suside created this gist Apr 20, 2017.
    11 changes: 11 additions & 0 deletions HAProxy_and_K8s.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    ### Kubernetes + HAProxy sticky session affinity
    1. Make sure you have `balance source` in haproxy.
    1. Backend `server` section in haproxy config should have all your k8s nodes.
    1. `sessionAffinity` in k8s is irrelevant.
    1. Exposed k8s service need to have `nodePort` set and this annotation:

    `kubectl annotate service myService service.beta.kubernetes.io/external-traffic=OnlyLocal`

    This will cause internal k8s loadbalancer on nodeⁿ to route traffic only to pod on nodeⁿ. From Haproxy point of view it will look like `nodeⁿ:nodePort` === `pod on nodeⁿ:port` thus disabling k8s LB completly.

    Further reading: https://kubernetes.io/docs/tutorials/services/source-ip/#source-ip-for-services-with-typenodeport