当前位置: 首页>后端>正文

Nomad系列-Nomad网络模式

绯诲垪鏂囩珷

  • Nomad 绯诲垪鏂囩珷

姒傝堪

Nomad 鐨勭綉缁滃拰 Docker 鐨勪篃鏈夊緢澶т笉鍚? 鍜?K8s 鐨勬湁寰堝ぇ涓嶅悓. 鍙﹀, Nomad 涓嶅悓鐗堟湰(Nomad 1.3 鐗堟湰鍓嶅悗)鎴栨槸鍚﹂泦鎴?Consul 鍙?CNI 绛変笉鍚岀粍浠朵篃浼氬鑷寸綉缁滄ā寮忓悇涓嶇浉鍚? 鏈枃璇︾粏姊崇悊涓€涓?Nomad 鐨勪富瑕佸嚑绉嶇綉缁滄ā寮?/p>

鍦∟omad 1.3鍙戝竷涔嬪墠锛屽畠鑷韩骞朵笉鏀寔鍙戠幇闆嗙兢涓繍琛岀殑鍏朵粬搴旂敤绋嬪簭銆傚湪闆嗙兢涓皟搴︿换鍔℃椂锛岃繖鏄竴涓潪甯稿熀鏈殑瑕佹眰銆侼omad渚濊禆浜嶤onsul鏉ュ彂鐜板叾浠栤€滄湇鍔♀€濓紝骞朵负娉ㄥ唽鍜岃幏鍙栨湇鍔¤褰曟彁渚涗竴娴佺殑鏀寔锛岃繖浣垮緱浜嬫儏鍙樺緱鏇村鏄撱€侰onsul閫氳繃鍚勭鏈哄埗鎻愪緵璁板綍锛屼緥濡俁EST API锛孌NS鍜孋onsul妯℃澘锛岃繖浜涙ā鏉垮湪鍙互娉ㄥ叆鍒板簲鐢ㄧ▼搴忎腑鐨凣o妯℃澘涓憟鐜版湇鍔$殑纭垏IP/绔彛銆?/p>

瀛︿範 Nomad 鐨勪竴涓毦鐐瑰湪浜? Nomad 寰€寰€鍜?Consul 涓€璧疯繍琛? 閭d箞瀵逛簬杩欑鎯呭喌鏉ヨ锛屼竴涓富瑕佺殑瀛︿範鏇茬嚎鏄紝鎴戜滑蹇呴』棣栧厛浜嗚ВConsul鏄浣曞伐浣滅殑锛岄儴缃蹭竴涓狢onsul闆嗙兢, 鍚屾椂瑕佽瀺浼氳疮閫?2 涓蒋浠跺氨寰堥毦浜嗐€侼omad 1.3 瑙e喅浜嗚繖涓棶棰樼殑涓€閮ㄥ垎锛堝嵆涓嶉渶瑕佽繍琛孋onsul灏卞彲浠ヨ繘琛屽熀鏈殑鏈嶅姟鍙戠幇锛夛紝闈炲父閫傚悎鍒氬垰寮€濮嬩娇鐢ㄥ熀浜嶯omad鐨勭綉缁溿€?/p>

鍦烘櫙涓€: 鍦ㄤ富鏈轰笂鍏紑搴旂敤

Nomad系列-Nomad网络模式,第1张
Host Dynamic Port

浠庢渶绠€鍗曠殑鐢ㄤ緥寮€濮嬶細浣犳湁涓€涓?redis 瀹瑰櫒锛屼綘鎯虫妸瀹冩毚闇茬粰涓绘満銆?鐩稿綋浜庢垜浠兂瑕佸仛鐨?code>docker run鏄?锛?/p>

docker run --rm -p=6379 redis

姝ゅ懡浠ゅ叕寮€涓绘満涓婄殑鍔ㄦ€?/strong>绔彛銆傝鏌ョ湅绔彛鍙峰埌搴曟槸浠€涔堬紝鎮ㄥ彲浠ユ墽琛?docker ps 骞跺湪 PORTS 涓嬫壘鍒扮被浼间簬 0.0.0.0:49153->6379/tcp 鐨勮緭鍑恒€?/p>

$ redis-cli -p 49153                
127.0.0.1:49153> ping
PONG

閭d箞, 鍦?Nomad 涓浉鍚岀殑鎿嶄綔濡備綍瀹炵幇

job "redis" {
  type        = "service"

  group "redis" {
    network {
      mode = "host"
      port "redis" {
        to = 6379
      }
    }

    task "redis" {
      driver = "docker"

      config {
        image = "redis"
        ports = ["redis"]
      }
    }
  }
}

鍦ㄥ嚑琛岄厤缃腑锛屾垜浠湁涓€涓鍦ㄨ繍琛岀殑Docker瀹瑰櫒锛屽畠鍏紑浜嗕竴涓姩鎬佺鍙?30627:

Nomad系列-Nomad网络模式,第2张
Nomad Redis Job Map Port

鎴戜滑鍙互閫氳繃涓绘満涓婄殑 redis-cli 杩炴帴鍒板畠锛?/p>

$ redis-cli -p 30627
127.0.0.1:30627> ping
PONG

馃惥Warning锛?/p>

鍦?task.config 閮ㄥ垎涓湁 ports 寰堥噸瑕併€侼omad灏嗘淇℃伅浼犻€掔粰涓绘満涓婅繍琛岀殑 docker 瀹堟姢杩涚▼銆傚洜姝わ紝闄ら潪鎮ㄦ寚瀹氬湪瀹瑰櫒涓€氬憡鍝簺绔彛锛屽惁鍒欏畠涓嶄細鐭ラ亾鏄惁瑕佸叕寮€6379銆?/p>

鏆撮湶闈欐€佺鍙?/h3>

涓€绉嶄笉澶父瑙佺殑鎯呭喌鏄皢搴旂敤绋嬪簭缁戝畾鍒颁富鏈轰笂鐨勯潤鎬佺鍙? 鍙渶鍦?port 鍧椾腑娣诲姞涓€涓?static 琛岋細

    network {
      port "redis" {
        static = 6379
      }
    }
Nomad系列-Nomad网络模式,第3张
Host Static Port

褰撴垜浠啀娆¢儴缃茬浉鍚岀殑鏂囦欢鏃讹紝鎴戜滑鍙互鐪嬪埌绔彛鍒嗛厤宸茬粡浠庡姩鎬佺鍙f洿鏀逛负鎴戜滑鍒嗛厤鐨勯潤鎬佺鍙c€備絾鏄敞鎰忛渶瑕佺‘淇濇病鏈夊叾浠栧簲鐢ㄧ▼搴忎睛鍚悓涓€鎺ュ彛鍜岀鍙o紝鍚﹀垯蹇呯劧浼氬鑷村啿绐併€?/p>

闈欐€佺鍙e吀鍨嬬殑浣跨敤鍦烘櫙灏辨槸: Ingress. 姣斿 Traefik 鍙互浣跨敤闈欐€佺鍙g洃鍚?80 鍜?443.

鍦烘櫙浜? 涓庡悓涓€ Group 鍐呯殑 Redis 閫氫俊

瀵逛簬杩欎釜鍦烘櫙锛屾垜浠亣璁炬湁涓€涓簲鐢ㄧ▼搴忛渶瑕佷笌Redis閫氫俊銆傚湪杩欎釜鍦烘櫙涓紝Redis鐢ㄩ€旀槸涓存椂缂撳瓨锛屾墍浠ュ彲浠ュ皢瀹冧滑閮ㄧ讲鍦ㄥ悓涓€涓?Group 涓€?/p>

涓€涓?Group 鍙互鍖呭惈澶氫釜 Task銆傝繖閲岄渶瑕佺煡閬撶殑閲嶈涓€鐐规槸锛屽悓涓€ Group 灏嗗缁堝叿鏈夎嚜宸辩殑鍏变韩缃戠粶鍛藉悕绌洪棿(绫讳技K8s涓璓od涓殑澶氫釜Container鍏锋湁鍏变韩缃戠粶鍛藉悕绌洪棿)銆傝繖鎰忓懗鐫€锛屽鏋滄偍鍦ㄧ粍涓湁2涓?Task锛屽垯瀹冧滑閮藉彲浠ヨ闂浉鍚岀殑缃戠粶鍛藉悕绌洪棿銆傝繖鍏佽涓や釜 Task 鍦ㄥ悓涓€缃戠粶鎺ュ彛涓婄浉浜掗€氫俊銆?/p>

job "hello" {
  type        = "service"

  group "app" {
    network {
      mode = "host"
      port "app" {
        static = 8080
      }
      port "redis" {
        static = 6379
      }
    }

    task "redis" {
      driver = "docker"

      config {
        network_mode = "host"
        image        = "redis"
        ports        = ["redis"]
      }
    }


    task "app" {
      driver = "docker"
      env {
        DEMO_REDIS_ADDR = "${NOMAD_ADDR_redis}"
      }

      config {
        network_mode = "host"
        image        = "mrkaran/hello-app:1.0.0"
        ports        = ["app"]
      }
    }
  }
}

璇︾粏璇存槑濡備笅:

  • 鎮ㄥ彲浠ョ湅鍒版垜浠湪鍚屼竴 Group 涓嬪畾涔変簡 task app 鍜宼ask redis 銆傝繖鎰忓懗鐫€Nomad灏嗗湪鍚屼竴瀹㈡埛绔?/strong>涓婂叡鍚屽畾浣嶈繖涓や釜Task锛堝洜涓哄畠浠笉浠呭€惧悜浜庡叡浜浉鍚岀殑缃戠粶鍛藉悕绌洪棿锛岃€屼笖杩樺叡浜叕鍏卞垎閰嶇洰褰?杩欎娇寰楄法浠诲姟鍏变韩鏂囦欢鍙樺緱闈炲父瀹规槗锛夈€?/li>
  • 鎴戜滑浣跨敤 NOMAD_ADDR_redis 鏉ヨ幏鍙?redis task 鐨?IP:Port 缁勫悎銆傝繖鍦ㄨ繍琛屾椂鐢盢omad娉ㄥ叆銆傛偍鍙互鍦ㄨ繖閲屾壘鍒拌繍琛屾椂鐜鍙橀噺鐨勫垪琛ㄣ€?/li>
  • 杩欐槸蹇€熸祴璇?寮€鍙戣缃殑鐞嗘兂閫夋嫨锛屽洜涓烘偍涓嶅笇鏈涙湇鍔″彂鐜扮瓑闂锛屽苟涓斿笇鏈涗互鏈€灏忕殑浠d环杩炴帴鍒版偍鐨勫簲鐢ㄧ▼搴忋€?/li>

濡傛灉鎮ㄨ浠庡熀浜?docker-compose 鐨勭幆澧冭縼绉伙紝浠ヤ笂閰嶇疆闈炲父閫傚悎(浣嗘槸瀹炵幇杩樻槸涓嶅悓, Nomad鍒╃敤浜嗕富鏈虹綉缁?锛屾偍鍙互灏嗘妯℃澘鐢ㄤ簬鎮ㄧ殑鏈嶅姟銆傝繖绉嶆柟娉曠殑鏈€澶ч檺鍒舵槸瀹冧娇鐢?strong>涓绘満缃戠粶銆?/p>

鍦烘櫙涓? 璺ㄤ笉鍚岀殑 Group 杩涜閫氫俊

濡備笂鎵€杩? 濡傛灉鎮ㄦ湁鐩稿叧鐨?Task锛堝init task锛屾偍甯屾湜鍦?task 寮€濮嬪墠鑾峰彇鏂囦欢锛夛紝鍚屼竴涓?Group 寰堟湁鐢?绫讳技K8s Pod 鐨?init container)銆備絾鏄娇鐢?group 鐨勭己鐐规槸鎮ㄤ笉鑳界嫭绔嬪湴鎵╁睍 task銆傚湪涓婇潰鐨勪緥瀛愪腑锛屾垜浠皢Redis鍜孉pp鏀惧湪鍚屼竴涓?Group 涓紝浣嗚繖鎰忓懗鐫€濡傛灉浣犲鍔犲悓涓€涓?Group 鐨?count 鏉ユ墿灞?app锛屼綘鏈€缁堜篃浼氭墿灞昍edis瀹瑰櫒銆傝繖鏄笉鍙彇鐨勶紝鍥犱负Redis鍙兘涓嶉渶瑕佷笌搴旂敤绋嬪簭鎴愭瘮渚嬪湴鎵╁睍銆?/p>

鍒涘缓澶氫釜 Group 鐨勬柟娉曟槸灏嗕换鍔℃媶鍒嗗埌鍚勮嚜鐨勭粍涓細

job "hello" {
  type        = "service"

  group "app" {
    count = 1

    network {
      mode = "host"
      port "app" {
        static = 8080
      }
    }

    task "app" {
      driver = "docker"
      env {
        DEMO_REDIS_ADDR = "localhost:6379"
      }

      config {
        image = "mrkaran/hello-app:1.0.0"
        ports = ["app"]
      }
    }
  }

  group "redis" {
    count = 1

    network {
      mode = "host"
      port "redis" {
        static = 6379
      }
    }

    task "redis" {
      driver = "docker"

      config {
        image = "redis"
        ports = ["redis"]
      }
    }
  }
}

鎻愪氦姝?Job 鍚庯紝鎮ㄥ皢鑾峰緱2涓垎閰岻D锛堟瘡涓?Group 浼氬垱寤轰竴涓?alloc 锛夈€傝繖閲岀殑鍏抽敭鐐规槸杩欎袱涓?Group 閮芥湁鑷繁鐨勭綉缁滃懡鍚嶇┖闂淬€傚洜姝わ紝鎴戜滑瀹為檯涓婃病鏈変换浣曟柟娉曞彲浠ヨ闂叾浠栧簲鐢ㄧ▼搴忥紙鎴戜滑涓嶈兘鍚戜笂闈㈣繖鏍蜂緷璧栦富鏈虹綉缁滐紝鍥犱负鏃犳硶淇濊瘉杩欎袱涓?Group 閮介儴缃插湪鍚屼竴涓妭鐐逛笂锛夈€?/p>

鐜板湪鐢变簬缁勬槸鍒嗗紑鐨勶紝 app 瀹瑰櫒涓嶇煡閬?redis 锛堝弽涔嬩害鐒讹級锛?/p>

env | grep NOMAD
NOMAD_REGION=global
NOMAD_CPU_LIMIT=4700
NOMAD_IP_app=127.0.0.1
NOMAD_JOB_ID=hello
NOMAD_TASK_NAME=app
NOMAD_SECRETS_DIR=/secrets
NOMAD_CPU_CORES=1
NOMAD_NAMESPACE=default
NOMAD_ALLOC_INDEX=0
NOMAD_ALLOC_DIR=/alloc
NOMAD_JOB_NAME=hello
NOMAD_HOST_IP_app=127.0.0.1
NOMAD_SHORT_ALLOC_ID=a9da72dc
NOMAD_DC=dc1
NOMAD_ALLOC_NAME=hello.app[0]
NOMAD_PORT_app=8080
NOMAD_GROUP_NAME=app
NOMAD_PARENT_CGROUP=nomad.slice
NOMAD_TASK_DIR=/local
NOMAD_HOST_PORT_app=8080
NOMAD_MEMORY_LIMIT=512
NOMAD_ADDR_app=127.0.0.1:8080
NOMAD_ALLOC_PORT_app=8080
NOMAD_ALLOC_ID=a9da72dc-94fc-6315-bb37-63cbeef153b9
NOMAD_HOST_ADDR_app=127.0.0.1:8080

鏈嶅姟鍙戠幇

app Group 闇€瑕佸湪杩炴帴鍒?redis 涔嬪墠鍙戠幇瀹冦€傛湁澶氱鏂规硶鍙互鍋氬埌杩欎竴鐐癸紝浣嗘垜浠皢浠嬬粛涓ょ鏇村父瑙佺殑鏍囧噯鏂规硶銆?/p>

浣跨敤 Nomad Native Service Discovery

Nomad系列-Nomad网络模式,第4张
Nomad Native Service Discovery

杩欐槸鍦∟omad 1.3涓帹鍑虹殑鍔熻兘銆傚湪杩欐鍙戝竷涔嬪墠锛孨omad 涓嶅緱涓嶄緷闈?Consul 鏉ュ畬鎴愯繖涓€浠诲姟銆備絾鏄湁浜哊omad涓唴缃殑鍘熺敓鏈嶅姟鍙戠幇锛屼簨鎯呭氨绠€鍗曞浜嗐€傝鎴戜滑瀵逛綔涓氭枃浠惰繘琛屼互涓嬫洿鏀广€傚湪姣忎釜 Group 涓紝鎴戜滑灏嗘坊鍔犱竴涓?service 瀹氫箟锛?/p>

  group "app" {
    count = 1

    network {
      mode = "host"
      port "app" {
        to = 8080
      }
    }

    service {
      name     = "app"
      provider = "nomad"
      port     = "app"
    }
    // task is the same
  }

  group "redis" {
    count = 1

    network {
      mode = "host"
      port "redis" {
        to = 6379
      }
    }

    service {
      name     = "redis"
      provider = "nomad"
      port     = "redis"
    }
    // task is the same
  }

濡備笂锛屾垜浠坊鍔犱簡涓€涓柊鐨?service 鍧楋紝骞跺垹闄や簡 static 绔彛銆傚綋鎴戜滑浣跨敤鏈嶅姟鍙戠幇鏃讹紝涓嶉渶瑕佺粦瀹氬埌闈欐€佺鍙?/strong>銆?/p>

鎻愪氦浣滀笟鍚庯紝鎴戜滑鍙互浣跨敤 nomad service list 鍛戒护纭繚鏈嶅姟宸叉敞鍐屽埌Nomad銆?/p>

nomad service list    
Service Name  Tags
app           []
redis         []

瑕佷簡瑙g壒瀹氭湇鍔$殑璇︾粏淇℃伅锛屾垜浠彲浠ヤ娇鐢?nomad service info锛?/p>

$ nomad service info app      
Job ID  Address          Tags  Node ID   Alloc ID
hello   127.0.0.1:29948  []    d92224a5  5f2ac51f
$ nomad service info redis
Job ID  Address          Tags  Node ID   Alloc ID
hello   127.0.0.1:22300  []    d92224a5  8078c9a6

濡備笂, 鎴戜滑鍙互鐪嬪埌姣忎釜鏈嶅姟涓殑鍔ㄦ€佺鍙e垎閰嶃€傝鍦ㄦ垜浠殑搴旂敤绋嬪簭涓娇鐢ㄦ閰嶇疆锛屾垜浠皢鍏舵ā鏉垮寲锛?/p>

    task "app" {
      driver = "docker"

      template {
        data = <<EOH
{{ range nomadService "redis" }}
DEMO_REDIS_ADDR={{ .Address }}:{{ .Port }}
{{ end }}
EOH

        destination = "secrets/config.env"
        env         = true
      }

      config {
        image = "mrkaran/hello-app:1.0.0"
        ports = ["app"]
      }
    }

鎴戜滑娣诲姞浜?template 鑺傦紝瀹冨皢鍦ㄥ鍣ㄤ腑鎻掑叆鐜鍙橀噺銆傛垜浠亶鍘?nomadService 骞惰幏鍙?redis 鏈嶅姟鐨勫湴鍧€鍜岀鍙c€傝繖浣垮緱鍏朵粬鑺傜偣涓婄殑浠诲姟鍙互鏂逛究鍦板彂鐜板郊姝ゃ€?/p>

浣跨敤 Consul 鏈嶅姟鍙戠幇

Nomad系列-Nomad网络模式,第5张
Consul Service Discovery

鍙渶璋冩暣 service 鍧椾腑鐨?provider 锛屾垜浠氨鍙互浣跨敤Consul浠g悊杩涜鏈嶅姟鍙戠幇銆?/p>

    service {
      name     = "app"
      provider = "consul"
      port     = "app"
    }


    task "app" {
      driver = "docker"

      template {
        data = <<EOH
{{ range service "redis" }}
DEMO_REDIS_ADDR={{ .Address }}:{{ .Port }}
{{ end }}
EOH

馃惥Warning:

娉ㄦ剰 range nomadService 涔熸敼涓轰簡 range service

鍓嶆彁鏄纭繚姝e湪杩愯Consul骞跺凡灏哊omad杩炴帴鍒板畠銆傚叿浣撹鍙傞槄璇ユ枃妗c€?/p>

鍏朵綑鐨勪簨鎯呭嚑涔庝繚鎸佷笉鍙樸€傚彧鐢?strong>涓よ浠g爜灏卞彲浠ュ湪Nomad/Consul涔嬮棿鍒囨崲鏉ュ彂鐜版湇鍔°€?/p>

鍙﹀, 浣跨敤Consul浼氭湁鏇村鐨?strong>浼樺娍锛?/p>

  • 鍙互浣跨敤DNS鏌ヨ鏈嶅姟鐨勫湴鍧€锛?/li>
doggo redis.service.consul @tcp://127.0.0.1:8600
NAME                    TYPE    CLASS   TTL ADDRESS     NAMESERVER     
redis.service.consul.   A       IN      0s  172.20.10.3 127.0.0.1:8600  
  • 鍙敱Nomad浠ュ鐨勫簲鐢ㄧ▼搴忚闂€傚鏋?consul 琚玁omad闆嗙兢澶栫殑鍏朵粬搴旂敤绋嬪簭浣跨敤锛屽畠浠粛鐒跺彲浠ヨ幏寰楀搴旂殑鍦板潃锛堜娇鐢―NS鎴朢EST API锛?/li>

褰撶劧锛孨omad Native Service Discovery 闈炲父閫傚悎鏈湴/杈圭紭鐜璁剧疆锛岀敋鑷虫槸鐢熶骇涓殑杈冨皬鐢ㄤ緥锛屽洜涓哄畠涓嶅啀闇€瑕?Consul锛?/p>

鍦烘櫙鍥? 闄愬埗瀵规煇浜?Namespace 鐨勮闂?/h2>
Nomad系列-Nomad网络模式,第6张
Consul Service Mesh

鍦ㄤ笂杩版墍鏈夊満鏅腑锛屾垜浠彂鐜版湇鍔′細鏆撮湶缁欐湰鍦癗omad瀹㈡埛绔€傚鏋滄偍鍦ㄩ泦缇や笂杩愯澶氫釜 Namespace锛屾偍鍙兘甯屾湜鏍规湰涓嶅叕寮€瀹冧滑銆傛澶栵紝鎮ㄥ彲鑳藉笇鏈涜〃杈惧簲鐢ㄧ▼搴忓彲浠ヨ闂壒瀹氭湇鍔$殑缁嗙矑搴︽帶鍒躲€傛墍鏈夎繖浜涢兘鍙互閫氳繃鏈嶅姟缃戞牸瀹炵幇銆侼omad鎻愪緵浜嗕竴绉嶉€氳繃Consul Connect寤虹珛鈥滄湇鍔$綉鏍尖€濈殑鏂规硶銆侰onsul Connect鍙互杩涜mTLS鍜屾湇鍔℃巿鏉冦€傚湪寮曟搸鐩栦笅锛屽畠鏄竴涓笌鎮ㄧ殑搴旂敤绋嬪簭涓€璧疯繍琛岀殑Envoy浠g悊锛堟垨sidecar锛夈€?Consul 浠g悊涓烘偍閰嶇疆Envoy閰嶇疆锛屽洜姝よ繖涓€鍒囬兘闈炲父鏃犵紳銆?/p>

瑕佸仛鍒拌繖涓€鐐癸紝鎴戜滑棣栧厛闇€瑕佺殑鏄?bridge 缃戠粶妯″紡銆傛缃戠粶妯″紡瀹為檯涓婃槸涓€涓狢NI鎻掍欢锛岄渶瑕佸湪 /opt/cni/bin 涓崟鐙畨瑁呫€傛寜鐓ц繖閲屾彁鍒扮殑姝ラ:

    network {
      mode = "bridge"
      port "redis" {
        to = 6379
      }
    }

Redis 涓殑鏈嶅姟琚?Consul Connect Ingress 鎵€璋冪敤锛?/p>

    service {
      name     = "redis"
      provider = "consul"
      port     = "6379"
      connect {
        sidecar_service {}
      }
    }

杩欐槸涓€涓┖鍧楋紝鍥犱负鎴戜滑涓嶉渶瑕佸湪杩欓噷瀹氫箟浠讳綍涓婃父銆傚叾浣欏€煎皢涓洪粯璁ゅ€笺€?/p>

鎺ヤ笅鏉ワ紝鎴戜滑涓?app 鍒涘缓涓€涓湇鍔★紝杩欐槸涓€涓狢onsul Connect Egress锛?/p>

    service {
      name     = "app"
      provider = "consul"
      port     = "app"
      connect {
        sidecar_service {
          proxy {
            upstreams {
              destination_name = "redis"
              local_bind_port  = 6379
            }
          }
        }
      }
    }

杩欓噷鎴戜滑涓?redis 瀹氫箟涓€涓笂娓搞€傚湪杩欓噷锛屽綋 app 鎯宠涓巖edis閫氫俊鏃讹紝瀹冧細涓?localhost:6379 瀵硅瘽锛岃繖鏄疎nvoy sidecar姝e湪鐩戝惉鐨勬湰鍦扮鍙c€傛垜浠彲浠ヤ娇鐢?netstat 鏉ラ獙璇侊細

$ netstat -tulpvn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.2:19001         0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:23237           0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::8080                 :::*                    LISTEN      1/./hello.bin

娴侀噺浠庤繖涓鍙e彂閫佸埌瀹冮€氬憡鐨勭鍙d笂鐨勫彟涓€涓狤nvoy浠g悊锛堝苟涓擟onsul鑷姩閰嶇疆锛夈€傝Envoy浠g悊杩涗竴姝ュ皢娴侀噺鍙戦€佸埌绔彛6379涓婄殑 redis 瀹瑰櫒銆備唬鐞嗘祦閲忛€氳繃mTLS杩涜瀹夊叏鍔犲瘑骞舵巿鏉冿紙閫氳繃Consul Intentions -鏈枃涓嶅仛浠嬬粛锛夈€?/p>

鍦烘櫙浜? 鍚戞渶缁堢敤鎴峰叕寮€鏈嶅姟

Nomad系列-Nomad网络模式,第7张
LB + Ingress

鍦ㄧ涓€涓満鏅腑锛屾垜浠璁轰簡濡備綍浣跨敤闈欐€佺鍙c€備簨瀹炶瘉鏄庯紝濡傛灉浣犳兂瀹氫箟涓€涓猅raffic Ingress鏈嶅姟锛屽畠闈炲父鏈夌敤銆備笌K8s涓嶅悓鐨勬槸锛孨omad娌℃湁浠讳綍Ingress Controller锛屾墍浠ユ渶濂界殑鏂规硶鏄皢杩欎簺Web浠g悊浣滀负 system job 閮ㄧ讲鍦ㄦ瘡涓妭鐐逛笂锛堣繖鎰忓懗鐫€瀹冨彲浠ョ‘淇濆湪姣忎釜瀹㈡埛绔妭鐐逛笂杩愯锛夛紝骞跺皢瀹冧滑缁戝畾鍒伴潤鎬佺鍙o紙姣斿443/80锛夈€傜劧鍚庯紝閰嶇疆 LB 骞跺皢鎵€鏈塏omad鑺傜偣娉ㄥ唽涓?Target IP锛屽叾绔彛灏嗘槸鎮ㄥ畾涔夌殑闈欐€佺鍙c€傝繖浜汭ngress浠g悊锛堟瘮濡俆raefik/Nginx锛夊彲浠ラ€氳繃涓婇潰鎻愬埌鐨勪换浣曟ā寮忎笌鎮ㄧ殑搴旂敤绋嬪簭閫氫俊銆?/p>

馃摑Notes:

鍦ㄤ笂涓€绡囨枃绔犱腑, 鎴戜滑骞舵病鏈夐厤缃?LB 鍚庨潰瀵规帴鎵€鏈?Traefik.
鐩稿弽, 鎴戜滑鐩存帴璁块棶鏌愪竴涓壒瀹氳妭鐐圭殑 Traefik 鐨?80/443 绔彛.

閫氬父锛屾偍甯屾湜涓哄叆鍙d唬鐞嗕娇鐢ㄢ€滃熀浜庝富鏈衡€濈殑璺敱妯″紡鏉ュ仛鍑鸿矾鐢卞喅绛栥€?/p>

渚嬪锛屽鏋滄偍鏈変竴涓寚鍚慉LB鐨?a.example.org DNS璁板綍銆傜幇鍦紝褰撹姹傚埌杈続LB鏃讹紝瀹冧細杞彂鍒颁换浣曚竴涓猅raefik/NGINX銆備负浜嗕娇 NGINX 姝g‘鍦板皢娴侀噺璺敱鍒?code>a service锛屾偍鍙互浣跨敤鈥淗ost鈥濇姤澶淬€?/p>

鎬荤粨

杩欎簺鏄垜鎵€鐭ラ亾鐨勪竴浜涘父瑙佺殑缃戠粶妯″紡銆傜敱浜庡叾涓竴浜涙蹇靛苟涓嶆槸闈炲父绠€鍗曪紝鎴戝笇鏈涜В閲婃湁鍔╀簬甯︽潵涓€浜涙竻鏅般€?/p>

鍏充簬杩欎釜涓婚杩樻湁寰堝锛屾瘮濡?Consul Gateway 鍜屽绉岰NI锛屽畠浠彲浠ヨ皟鏁撮泦缇や腑鐨勭綉缁滅殑搴曞眰缁嗚妭锛屼絾杩欎簺閮芥槸涓€浜涢潪甯搁珮绾х殑涓婚锛岃秴鍑轰簡鏈枃鐨勮寖鍥淬€傚悗缁湁鏈轰細鍙互鍐嶅仛灞曞紑.

馃摎锔忓弬鑰冩枃妗?/h2>
  • Understanding Nomad Networking Patterns - YouTube
  • Understanding Networking in Nomad | Karan Sharma (mrkaran.dev)

涓変汉琛? 蹇呮湁鎴戝笀; 鐭ヨ瘑鍏变韩, 澶╀笅涓哄叕. 鏈枃鐢变笢椋庡井楦f妧鏈崥瀹?EWhisper.cn 缂栧啓.


https://www.xamrdz.com/backend/3gv1941284.html

相关文章: