Skip to content

Commit 031194e

Browse files
author
Dario Tranchitella
committed
Using NGINX as load balancer at TCP level
1 parent 9c9a66b commit 031194e

File tree

3 files changed

+84
-46
lines changed

3 files changed

+84
-46
lines changed

roles/lb/tasks/main.yml

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
---
2-
- name: Installing EPEL release
3-
yum:
4-
name: epel-release
5-
state: present
2+
- name: Installing EPEL release
3+
yum:
4+
name: epel-release
5+
state: present
66

7-
- name: Installing NGINX as Load Balancer
8-
package:
9-
name: nginx
10-
state: present
7+
- name: Installing NGINX as Load Balancer
8+
package:
9+
name: nginx
10+
state: present
1111

12-
- name: Setting systemd unit for NGINX
13-
systemd:
14-
name: nginx
15-
enabled: yes
16-
state: restarted
12+
- name: Setting systemd unit for NGINX
13+
systemd:
14+
name: nginx
15+
enabled: yes
16+
state: started
1717

18-
- name: Rendering NGINX configuration file
19-
template:
20-
dest: /etc/nginx/conf.d/default.conf
21-
src: default.conf.j2
18+
- name: Rendering NGINX configuration file
19+
template:
20+
dest: /etc/nginx/nginx.conf
21+
src: nginx.conf.j2
22+
register: state
2223

23-
- name: Deploying Kubernetes certificates
24-
copy:
25-
dest: "/root/{{ item }}"
26-
src: "{{ cert_path }}/{{ item }}"
27-
with_items:
28-
- kubernetes.pem
29-
- kubernetes-key.pem
30-
31-
- name: Reload NGINX configuration
32-
systemd:
33-
name: nginx
34-
state: reloaded
24+
- name: Reload NGINX configuration
25+
systemd:
26+
name: nginx
27+
state: reloaded
28+
when: state.changed

roles/lb/templates/default.conf.j2

Lines changed: 0 additions & 17 deletions
This file was deleted.

roles/lb/templates/nginx.conf.j2

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
user nginx;
2+
worker_processes auto;
3+
error_log /var/log/nginx/error.log;
4+
pid /run/nginx.pid;
5+
6+
7+
stream {
8+
upstream kube-api {
9+
{% for host in groups['controllers'] %}
10+
server {{ hostvars[host]['ansible_host'] }}:6443;
11+
{% endfor %}
12+
}
13+
14+
server {
15+
listen 6443;
16+
proxy_pass kube-api;
17+
}
18+
}
19+
20+
events {
21+
worker_connections 1024;
22+
}
23+
24+
include /etc/nginx/conf.d/*.conf;
25+
26+
http {
27+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
28+
'$status $body_bytes_sent "$http_referer" '
29+
'"$http_user_agent" "$http_x_forwarded_for"';
30+
31+
access_log /var/log/nginx/access.log main;
32+
33+
sendfile on;
34+
tcp_nopush on;
35+
tcp_nodelay on;
36+
keepalive_timeout 65;
37+
types_hash_max_size 2048;
38+
39+
include /etc/nginx/mime.types;
40+
default_type application/octet-stream;
41+
42+
server {
43+
listen 80 default_server;
44+
listen [::]:80 default_server;
45+
server_name _;
46+
root /usr/share/nginx/html;
47+
48+
include /etc/nginx/default.d/*.conf;
49+
50+
location / {
51+
}
52+
53+
error_page 404 /404.html;
54+
location = /40x.html {
55+
}
56+
57+
error_page 500 502 503 504 /50x.html;
58+
location = /50x.html {
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)