@@ -54,3 +54,91 @@ connecting to back-ends for re-encrypt terminated routes are stored in the
54
54
namespace and name of the route. The key, certificate, and CA certificate are
55
55
concatenated into a single file. You can use
56
56
link:https://www.openssl.org/[OpenSSL] to view the contents of these files.
57
+
58
+ == Customizing a Router
59
+
60
+ The HAProxy router is based on a golang template. This template generates the
61
+ HAProxy configuration file. If you would like to customize a router to meet
62
+ your needs you are able to change the template file, build a new docker image,
63
+ and run a customized router.
64
+
65
+ One common case for this may be implementing new features withing the
66
+ application backends. For instance, it might be desirable in a highly available
67
+ setup to use stick-tables that synchronizes between peers. The router
68
+ plugin provides all the facilities necessary to make this customization.
69
+
70
+ .Using Stick Tables
71
+
72
+ *Adding a Peer Section*
73
+
74
+ In order to synchronize stick tables amongst peers you must a define a peers
75
+ section in your HAProxy configuration. This section determines how HAProxy
76
+ will identify and connect to peers. The plugin provides data to the template
77
+ under the `.PeerEndpoints` variable to allow you to easily identify members
78
+ of the router service. You may add a peer section to the `haproxy-config.template`
79
+ by adding
80
+
81
+ [options="nowrap"]
82
+ ----
83
+ {{ if (len .PeerEndpoints) gt 0 }}
84
+ peers openshift_peers
85
+ {{ range $endpointID, $endpoint := .PeerEndpoints }}
86
+ peer {{$endpoint.TargetName}} {{$endpoint.IP}}:1937
87
+ {{ end }}
88
+ {{ end }}
89
+ ----
90
+
91
+
92
+ *Changing the Reload Script*
93
+
94
+ When using stick tables you have the option of telling HAProxy what it should
95
+ consider the name of the local host in the peer section. When creating endpoints the
96
+ plugin will attempt to set the `TargetName` to the value
97
+ of the endpoint's `TargetRef.Name`. If `TargetRef` is not set it will set the
98
+ `TargetName` to the IP address. Since the `TargetRef.Name` corresponds with the
99
+ Kubernetes host name you can add the `-L` option to the `reload-haproxy` script
100
+ to identify the local host in the peer section.
101
+
102
+ [options="nowrap"]
103
+ ----
104
+ # Must match an endpoint target name that is used in the peer section
105
+ peer_name=$HOSTNAME
106
+
107
+ if [ -n "$old_pid" ]; then
108
+ /usr/sbin/haproxy -f $config_file -p $pid_file -L $peer_name -sf $old_pid
109
+ else
110
+ /usr/sbin/haproxy -f $config_file -p $pid_file -L $peer_name
111
+ fi
112
+ ----
113
+
114
+ *Modifying Backends*
115
+
116
+ Finally, to use the stick tables within backends you may modify the HAProxy configuration
117
+ to use the stick-tables and peer set. Below is an example of changing the existing
118
+ backend for TCP connections to use stick-tables.
119
+
120
+ [options="nowrap"]
121
+ ----
122
+
123
+ {{ if eq $cfg.TLSTermination "passthrough" }}
124
+ backend be_tcp_{{$cfgIdx}}
125
+ balance leastconn
126
+ timeout check 5000ms
127
+ stick-table type ip size 1m expire 5m{{ if (len $.PeerEndpoints) gt 0 }} peers openshift_peers {{ end }}
128
+ stick on src
129
+ {{ range $endpointID, $endpoint := $serviceUnit.EndpointTable }}
130
+ server {{$endpointID}} {{$endpoint.IP}}:{{$endpoint.Port}} check inter 5000ms
131
+ {{ end }}
132
+ {{ end }}
133
+ ----
134
+
135
+ *Rebuilding Your Router*
136
+
137
+ Once you have made modifications to the router you must rebuild the docker image and push
138
+ it to your repository. Then you may specify your new image when creating a router either
139
+ in the pod's spec directly or by using the `oadm` command
140
+
141
+ [options="nowrap"]
142
+ ----
143
+ oadm router --credentials="$KUBECONFIG" --images=myrepo/myimage:mytag
144
+ ----
0 commit comments