当前位置:  首页>> 技术小册>> Kubernetes合辑1-安装Kubernetes

Nginx LB主要是用来给 Ingress Controller 负载流量以及为多个Master节点ApiServer负载流量。当前集群为单节点,可以不用配置ApiServer的负载均衡器,但为了方便后续扩展,这里也配置下负载均衡。

  1. [root@maxiaoke deploy-kubernetes]# gosh cmd -H 10.4.7.80 "yum install -y nginx nginx-mod-stream"
  2. [root@maxiaoke deploy-kubernetes]# gosh cmd -H 10.4.7.80 "mkdir /etc/nginx/conf.d/stream -p"
  3. [root@maxiaoke deploy-kubernetes]# gosh push -H 10.4.7.80 conf/nginx/nginx.conf /etc/nginx/
  4. [root@maxiaoke deploy-kubernetes]# gosh push -H 10.4.7.80 conf/nginx/apiserver.conf /etc/nginx/conf.d/stream/
  5. [root@maxiaoke deploy-kubernetes]# gosh cmd -H 10.4.7.80 "nginx -t"
  6. 10.4.7.80
  7. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  8. nginx: configuration file /etc/nginx/nginx.conf test is successful
  9. [root@maxiaoke deploy-kubernetes]# gosh cmd -H 10.4.7.80 "systemctl start nginx;systemctl enable nginx"

conf/nginx/nginx.conf:

  1. user nginx;
  2. worker_processes auto;
  3. error_log /var/log/nginx/error.log;
  4. pid /run/nginx.pid;
  5. include /usr/share/nginx/modules/*.conf;
  6. events {
  7. worker_connections 4096;
  8. }
  9. http {
  10. sendfile on;
  11. tcp_nopush on;
  12. tcp_nodelay on;
  13. keepalive_timeout 65;
  14. types_hash_max_size 2048;
  15. include /etc/nginx/mime.types;
  16. default_type application/octet-stream;
  17. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
  18. ssl_prefer_server_ciphers on;
  19. log_format access '$time_local|$remote_addr|$upstream_addr|$status|'
  20. '$upstream_connect_time|$bytes_sent|'
  21. '$upstream_bytes_sent|$upstream_bytes_received' ;
  22. access_log /var/log/nginx/access.log access;
  23. error_log /var/log/nginx/error.log;
  24. gzip on;
  25. map $http_upgrade $connection_upgrade {
  26. default upgrade;
  27. '' close;
  28. }
  29. include /etc/nginx/conf.d/http/*.conf;
  30. }
  31. stream {
  32. log_format proxy '$time_local|$remote_addr|$upstream_addr|$protocol|$status|'
  33. '$session_time|$upstream_connect_time|$bytes_sent|$bytes_received|'
  34. '$upstream_bytes_sent|$upstream_bytes_received' ;
  35. access_log /var/log/nginx/stream_access.log proxy;
  36. error_log /var/log/nginx/stream_error.log;
  37. include /etc/nginx/conf.d/stream/*.conf;
  38. }

conf/nginx/apiserver.conf:

  1. upstream kube-apiserver {
  2. server 10.4.7.81:6443 max_fails=1 fail_timeout=60s ;
  3. # server 10.4.7.82:6443 max_fails=1 fail_timeout=60s ;
  4. # server 10.4.7.83:6443 max_fails=1 fail_timeout=60s ;
  5. }
  6. server {
  7. listen 0.0.0.0:6443 ;
  8. allow 192.168.0.0/16;
  9. allow 10.0.0.0/8;
  10. deny all;
  11. proxy_connect_timeout 2s;
  12. proxy_next_upstream on;
  13. proxy_next_upstream_timeout 5;
  14. proxy_next_upstream_tries 1;
  15. proxy_pass kube-apiserver;
  16. access_log /var/log/nginx/kube-apiserver.log proxy;
  17. }

该分类下的相关小册推荐: