k8s待研究項

gself發表於2019-04-04
  • 如何測試一個服務在叢集內的效能?
  • kube-proxy的獲取不到iptables lock問題。
  • 使用nginx做微服務gateway,其配置使用upstream方式的風險,與另一種替代方案。
    1. 使用upstream的nginx配置檔案
      kubectl describe cm pasp-nginx-conf -n shb-sf-stg-ce9ef3aa
      #user  nobody;
      worker_processes  1;
      
      error_log  logs/error.log;
      
      pid        logs/nginx.pid;
      
      events {
          worker_connections  1024;
      }
      
      http {
          include       /wls/apache/nginx/nginx-1.13.3/conf/mime.types;
          default_type  application/octet-stream;
      
          #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
          #                  '$status $body_bytes_sent "$http_referer" '
          #                  '"$http_user_agent" "$http_x_forwarded_for"';
      
          #access_log  logs/access.log  main;
      
          sendfile        on;
          #tcp_nopush     on;
      
          #keepalive_timeout  0;
          keepalive_timeout  65;
      
           client_max_body_size 50M;
          log_format access '$remote_addr - $remote_user [$time_local] "$request"' '$status $body_bytes_sent "$http_referer"' '"$http_user_agent" $http_x_forwarded_for';
      
          #gzip  on;
      
          upstream pasp_core_web_upstream {
              server pasp-core-web-ui:7910;
          }
      
          upstream pasp_ws_web_upstream {
              server pasp-ws-web-ui:7910;
          }
      
          upstream aiknow_benifit_web_upstream{
              server icmp-aiknow-web-benefit-ui:7910;
          }
      
          upstream aiknow_verify_web_upstream {
              server icmp-aiknow-web-verify-ui:7910;
          }
      
          upstream pasp_aiknow_amlbl_web_upstream {
              server icmp-aiknow-web-amlbl-ui:7910;
          }
      
      
          upstream pasp_nmpr_web_upstream {
              server pasp-nmpr-web-ui:7910;
          }
      
          upstream pasp_pprk_web_upstream {
              server pasp-pprk-web-ui:7910;
          }
      
          upstream pasp_aiknow_web_rcbl_upstream {
              server pasp-aiknow-web-rcbl-ui:7910;
          }
      
          upstream pasp_eeportal_web_upstream {
              server pasp-eeportal-web-ui:7910;
          }
      
          upstream pasp_ira_web_upstream {
              server pasp-ira-web-ui:7910;
          }
      
          upstream fp_api_gateway_upstream {
              server fp-core-api-gateway.shb-sf-fp-core-stg-8af201ff:8086;
          }
      
      
          server {
              listen       7910;
              server_name  localhost;
      
          access_log  logs/host.access.log access;
      
              #charset koi8-r;
      
              #access_log  logs/host.access.log  main;
          location = / {
              proxy_set_header Host $http_host;
              proxy_set_header X-Forwarded-Host $host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-Server $host;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              add_header Cache-Control no-store;
              proxy_pass http://pasp_core_web_upstream/pasp-web/index.html;
              }
      
              location  ~* ^/pasp-web\/(.*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$) {
              proxy_set_header Host $http_host;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  add_header Cache-Control no-store;
                  proxy_pass  http://pasp_core_web_upstream;
              }
      
              location ^~ /ws-web/ {
                  proxy_set_header Host $http_host;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  add_header Cache-Control no-store;
                  proxy_pass  http://pasp_ws_web_upstream;
              }
      
              location ^~ /aiknow-benefit-web/ {
                  proxy_set_header Host $http_host;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  add_header Cache-Control no-store;
                  proxy_pass  http://aiknow_benifit_web_upstream;
              }
      
              location ^~ /aiknow-verify-web/ {
                  proxy_set_header Host $http_host;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  add_header Cache-Control no-store;
                  proxy_pass  http://aiknow_verify_web_upstream;
              }
      
              location ^~ /aiknow-amlbl-web/ {
                  proxy_set_header Host $http_host;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  add_header Cache-Control no-store;
                  proxy_pass  http://pasp_aiknow_amlbl_web_upstream;
              }
      
      
              location ^~ /nmpr-web/ {
                  proxy_set_header Host $http_host;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  add_header Cache-Control no-store;
                  proxy_pass  http://pasp_nmpr_web_upstream;
              }
      
              location ^~ /pprk-web/ {
                  proxy_set_header Host $http_host;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  add_header Cache-Control no-store;
                  proxy_pass  http://pasp_pprk_web_upstream;
              }
      
              location ^~ /aiknow-rcbl-web/ {
                  proxy_set_header Host $http_host;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  add_header Cache-Control no-store;
                  proxy_pass  http://pasp_aiknow_web_rcbl_upstream;
              }
      
              location ^~ /eeportal-web/ {
                  proxy_set_header Host $http_host;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  add_header Cache-Control no-store;
                  proxy_pass  http://pasp_eeportal_web_upstream;
              }
      
              location ^~ /ira-web/ {
                  proxy_set_header Host $http_host;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  add_header Cache-Control no-store;
                  proxy_pass  http://pasp_ira_web_upstream;
              }
      
              location / {
                  proxy_connect_timeout 3s;
                  proxy_read_timeout 300s;
                  proxy_send_timeout 3s;
                  proxy_set_header Host $http_host;
                  proxy_set_header X-Forwarded-Host $host;
                  proxy_set_header X-Real-IP $remote_addr;
                  proxy_set_header X-Forwarded-Server $host;
                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                  add_header Cache-Control no-store;
                  proxy_pass  http://fp_api_gateway_upstream;
              }
      
              error_page   500 502 503 504  /50x.html;
              location = /50x.html {
                  root   html;
              }
          }
      }
      
      複製程式碼
    2. 不使用upstream的替代方案
    kubectl describe cm pasp-nginx-conf -n shb-sf-stg-949093af
    #user  nobody;
    worker_processes  1;
    
    error_log  logs/error.log;
    
    pid        logs/nginx.pid;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       /wls/apache/nginx/nginx-1.13.3/conf/mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
         client_max_body_size 50M;
        log_format access '$remote_addr - $remote_user [$time_local] "$request"' '$status $body_bytes_sent "$http_referer"' '"$http_user_agent" $http_x_forwarded_for';
    
        #gzip  on;
    
        server {
            listen       7910;
            server_name  localhost;
    
        access_log  logs/host.access.log access;
    
            #charset koi8-r;
        resolver 172.254.0.2 valid=2s;
    
            #access_log  logs/host.access.log  main;
        location = / {
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            add_header Cache-Control no-store;
            #proxy_pass http://pasp_core_web_upstream/pasp-web/index.html;
            set $backend_servers pasp-core-web-ui.shb-sf-stg-949093af.svc.cluster.local.;
            proxy_pass http://$backend_servers:7910/pasp-web/index.html;
            }
    
            location  ~* ^/pasp-web\/(.*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$) {
                #resolver 127.0.0.11;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                add_header Cache-Control no-store;
                #proxy_pass  http://pasp_core_web_upstream;
                set $backend_servers pasp-core-web-ui.shb-sf-stg-949093af.svc.cluster.local.;
                proxy_pass http://$backend_servers:7910;
    
            }
    
            location ^~ /ws-web/ {
                #resolver 127.0.0.11;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                add_header Cache-Control no-store;
                #proxy_pass  http://pasp_ws_web_upstream;
                set $backend_servers pasp-ws-web-ui.shb-sf-stg-949093af.svc.cluster.local.;
                proxy_pass http://$backend_servers:7910;
    
            }
    
            location ^~ /aiknow-benefit-web/ {
                #resolver 127.0.0.11;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                add_header Cache-Control no-store;
                #proxy_pass  http://pasp_aiknow_benefit_web_upstream;
                set $backend_servers pasp-aiknow-web-benefit-ui.shb-sf-stg-949093af.svc.cluster.local.;
                proxy_pass http://$backend_servers:7910;
            }
    
            location ^~ /aiknow-amlbl-web/ {
                #resolver 127.0.0.11;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                add_header Cache-Control no-store;
                #proxy_pass  http://pasp_aiknow_amlbl_web_upstream;
                set $backend_servers icmp-aiknow-web-amlbl-ui.shb-sf-stg-949093af.svc.cluster.local.;
                proxy_pass http://$backend_servers:7910;
            }
    
            location ^~ /aiknow-rcbl-web/ {
                #resolver 127.0.0.11;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                add_header Cache-Control no-store;
                #proxy_pass  http://pasp_aiknow_amlbl_web_upstream;
                set $backend_servers pasp-aiknow-web-rcbl-ui.shb-sf-stg-949093af.svc.cluster.local.;
                proxy_pass http://$backend_servers:7910;
            }
    
             location ^~ /eeportal-web/ {
                #resolver 127.0.0.11;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                add_header Cache-Control no-store;
                #proxy_pass  http://pasp_aiknow_amlbl_web_upstream;
                set $backend_servers pasp-eeportal-web-ui.shb-sf-stg-949093af.svc.cluster.local.;
                proxy_pass http://$backend_servers:7910;
            }
    
    
            #location ^~ /nmpr-web/ {
            #    resolver 127.0.0.11;
            #    proxy_set_header Host $http_host;
            #    proxy_set_header X-Forwarded-Host $host;
            #    proxy_set_header X-Real-IP $remote_addr;
            #    proxy_set_header X-Forwarded-Server $host;
            #    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #    add_header Cache-Control no-store;
            #    proxy_pass  http://pasp_nmpr_web_upstream;
            #}
    
            location / {
                #resolver 127.0.0.11;
                proxy_set_header Host $http_host;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                add_header Cache-Control no-store;
                #proxy_pass  http://fp_api_gateway_upstream;
                set $backend_servers fp-core-api-gateway.shb-sf-fp-core-stg-5066f14b.svc.cluster.local.;
                proxy_pass http://$backend_servers:8086;
            }
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }
    複製程式碼

相關文章