kong命令(四)upstream


介紹

upstream 就是一個虛擬的服務。可用於配置多個target目標服務時實現負載均衡的效果。

注意:service的host指的就是upstream的name。

同時upstream提供了一個health check方法,用於檢查target目標服務是否健康。以此控制啟用或禁用target目標服務

 

和upstream關聯的kong模塊:service ,target

 

主要參數:algorithm 負載算法:round-robin(默認)consistent-hashing, or least-connections

healthchecks.active.http_path 健康檢查路徑:默認/,該地址是指在目標服務器上,適用於目標服務器的所有請求

 

命令

1、add upstream

方法 post

api:/upstreams

 

2,list upstream ,retrieve upstream

方法:get

api:/upstreams

/upstreams/upstream id or name

/targets/{target host:port or id}/upstream   關聯指定target目標服務的upstream

 

 

3,update upstream

方法:patch

api:/upstreams/{upstream name or id}

/targets/{target host:port or id}/upstream

 

4,create or update upstream

方法:put

api:/upstreams/{upstream name or id}

/targets/{target host:port or id}/upstream

5,delete

方法:delete

api:/upstreams/{upstream name or id}

/targets/{target host:port or id}/upstream

 

健康檢查 health check

kong會發起對配置在upstream上的所有target進行健康檢查,若檢查失敗,將會暫時移除不健康的target服務。

恢復之后會再次加入。具體參數可在upstream參數中配置。

檢查結果主要為一下四大類(官網介紹)

  • If a Target fails to be activated in the balancer due to DNS issues, its status displays as DNS_ERROR.
  • When health checks are not enabled in the Upstream configuration, the health status for active Targets is displayed as HEALTHCHECKS_OFF.
  • When health checks are enabled and the Target is determined to be healthy, either automatically or manually, its status is displayed as HEALTHY. This means that this Target is currently included in this Upstream’s load balancer execution.
  • When a Target has been disabled by either active or passive health checks (circuit breakers) or manually, its status is displayed as UNHEALTHY. The load balancer is not directing any traffic to this Target via this Upstream.

上述HEALTHY 、HEALTHCHECKS_OFF情況,target目標可以被轉發請求,其他兩類不被負載轉發。

查看:get方法。api:/upstreams/{name or id}/health/


 

人生在世,雜事七八;飯要少吃,事要多知;抽個時間,總結一下;樂在分享,自在提升 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM