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

有状态软件如何在 k8s 上快速扩容甚至自动扩容

姒傝堪

鍦ㄤ紶缁熺殑铏氭満/鐗╃悊鏈虹幆澧冮噷, 濡傛灉鎴戜滑鎯宠瀵逛竴涓湁鐘舵€佸簲鐢ㄦ墿瀹? 鎴戜滑闇€瑕佸仛鍝簺姝ラ

  1. 鐢宠铏氭満/鐗╃悊鏈?/li>
  2. 瀹夎渚濊禆
  3. 涓嬭浇瀹夎鍖?/li>
  4. 鎸夎鑼冮厤缃富鏈哄悕, hosts
  5. 閰嶇疆缃戠粶: 鍖呮嫭鍩熷悕, DNS, 铏?ip, 闃茬伀澧?..
  6. 閰嶇疆鐩戞帶

浠婂ぉ铏氭満鐜涓婂嚭鐜颁簡闂, 鏄洜涓?RabbitMQ 璧勬簮涓嶈冻. 鎵嬪姩鎵╁鐨勮繃绋嬩腑鑺辫垂浜嗚緝闀跨殑鏃堕棿.

浣嗘槸鍦?K8S 涓? 鏈夌姸鎬佸簲鐢ㄧ殑鎵╁灏卞緢绠€鍗? YAML 閲屾敼涓€涓?code>replicas鍓湰鏁? 绛変笉鍒?1min 灏辨墿瀹瑰畬姣?

褰撶劧, 鏈€鍩烘湰鐨? 涓嬮暅鍍? 鍚姩 pod(鐩稿綋浜庝笂杈圭殑鍓?3 姝?, 灏变笉蹇呭鎻? 閭d箞, 杩樻湁鍝簺鍥犵礌, 璁╂湁鐘舵€佸簲鐢ㄥ彲浠ュ湪 k8s 涓婂揩閫熸墿瀹圭敋鑷宠嚜鍔ㄦ墿瀹瑰憿

鍘熷洜灏辨槸杩欎袱鐐?

  1. peer discovery +peer discovery 鐨?鐩稿叧瀹炵幇(閫氳繃 hostname, dns, k8s api 鎴栧叾浠?
  2. 鍙瀵熸€?+ 鑷姩浼哥缉

鎴戜滑浠婂ぉ閫夋嫨鍑犱釜鍏稿瀷鐨勬湁鐘舵€佸簲鐢? 涓€涓€姊崇悊涓?

  1. Eureka
  2. Nacos
  3. Redis
  4. RabbitMQ
  5. Kafka
  6. TiDB

K8S 涓婃湁鐘舵€佸簲鐢ㄦ墿瀹?/h2>

鍦?Kubernetes 涓? 鏈夌姸鎬佸簲鐢ㄥ揩閫熸墿瀹圭敋鑷宠嚜鍔ㄦ墿瀹瑰緢瀹规槗. 杩欏緱鐩婁簬 Kubernetes 浼樼鐨勮璁′互鍙婅壇濂界殑鐢熸€? Kubernetes 灏卞儚鏄竴涓簯鍘熺敓鏃朵唬鐨勬搷浣滅郴缁? 瀹冭嚜韬氨鍏锋湁:

  1. 鑷姩鍖栧伐鍏?
  2. 鍐呴儴鏈嶅姟鍙戠幇 + 璐熻浇鍧囪 
  3. 鍐呴儴 DNS
  4. 鍜?Prometheus 鏁村悎
  5. 缁熶竴鐨勫0鏄庡紡 API
  6. 鏍囧噯, 寮€婧愮殑鐢熸€佺幆澧?

鎵€浠? 闇€瑕佹墿瀹? 涓€涓?yaml 鎼炲畾鍏ㄩ儴. 鍖呮嫭涓婅竟鎻愬埌鐨? 涓嬭浇, 瀹夎, 瀛樺偍閰嶇疆, 鑺傜偣鍙戠幇, 鍔犲叆闆嗙兢, 鐩戞帶閰嶇疆...

Eureka 鎵╁

有状态软件如何在 k8s 上快速扩容甚至自动扩容,第1张
eureka

馃敄 澶囨敞:

鏈夌姸鎬佹墿瀹圭涓€灞?

StatefulSet + Headless Service

eureka 鐨勬墿瀹瑰湪 K8S 鏈夌姸鎬佸簲鐢ㄤ腑鏄渶绠€鍗曠殑, 灏辨槸:

headless service + statefulset

Eureka 瑕佹墿瀹? 鍙 eureka 瀹炰緥褰兼鑳界浉浜掑彂鐜板氨鍙互. headless service 鍦ㄨ繖绉嶆儏鍐典笅灏辨淳涓婄敤鍦轰簡, 灏辨槸璁╁郊姝ゅ彂鐜?

Eureka 鐨勪竴涓畬鏁撮泦缇?yaml, 濡備笅:璇︾粏璇存槑濡備笅:

apiVersion: v1
kind: Service
metadata:
  name: eureka
  namespace: ms
spec:
  clusterIP: None
  ports:
    - name: eureka
      port: 8888
  selector:
    project: ms
    app: eureka
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: eureka
  namespace: ms
spec:
  serviceName: eureka
  replicas: 3
  selector:
    matchLabels:
      project: ms
      app: eureka
  template:
    metadata:
      labels:
        project: ms
        app: eureka
    spec:
      terminationGracePeriodSeconds: 10   
      imagePullSecrets:
      - name: registry-pull-secret
      containers:
        - name: eureka
          image: registry.example.com/kubernetes/eureka:latest
          ports:
            - protocol: TCP
              containerPort: 8888
          env:
            - name: APP_NAME
              value: "eureka"
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: APP_OPTS
              value: "
                     --eureka.instance.hostname=${POD_NAME}.${APP_NAME}
                     --registerWithEureka=true
                     --fetchRegistry=true
                     --eureka.instance.preferIpAddress=false
                     --eureka.client.serviceUrl.defaultZone=http://eureka-0.${APP_NAME}:8888/eureka/,http://eureka-1.${APP_NAME}:8888/eureka/,http://eureka-2.${APP_NAME}:8888/eureka/
  1. 閰嶇疆鍚嶄负eureka鐨?Service
  2. 鍦ㄥ悕涓?code>eureka鐨?statefulset 閰嶇疆涓?鍏?3 涓?eureka 鍓湰, 姣忎釜 eureka 鐨?HOSTNAME 涓? ${POD_NAME}.${SERVICE_NAME}. 濡? eureka-0.eureka
  3. 褰兼閫氳繃--registerWithEureka=true --fetchRegistry=true --eureka.instance.preferIpAddress=false --eureka.client.serviceUrl.defaultZone=http://eureka-0.${APP_NAME}:8888/eureka/,http://eureka-1.${APP_NAME}:8888/eureka/,http://eureka-2.${APP_NAME}:8888/eureka/閫氳繃 HOSTNAME 鐩镐簰娉ㄥ唽, 瀹屾垚浜嗛泦缇ょ殑鍒涘缓.

閭d箞, 濡傛灉瑕佸揩閫熸墿瀹瑰埌 5 涓?

  1. 璋冩暣 StatefulSet: replicas: 5
  2. 鍦ㄧ幆澧冨彉閲?code>APP_OPTS涓姞鍏ユ柊澧炵殑 2 涓壇鏈?hostname: http://eureka-3.${APP_NAME}:8888/eureka/,http://eureka-4.${APP_NAME}:8888/eureka/

鍗冲彲瀹屾垚.

Headless Service

鏈夋椂涓嶉渶瑕佹垨涓嶆兂瑕佽礋杞藉潎琛★紝浠ュ強鍗曠嫭鐨?Service IP銆?閬囧埌杩欑鎯呭喌锛屽彲浠ラ€氳繃鎸囧畾 Cluster IP锛?code>spec.clusterIP锛夌殑鍊间负 None 鏉ュ垱寤?Headless Service銆?/p>

鎮ㄥ彲浠ヤ娇鐢ㄦ棤澶?Service 涓庡叾浠栨湇鍔″彂鐜版満鍒惰繘琛屾帴鍙o紝鑰屼笉蹇呬笌 Kubernetes 鐨勫疄鐜版崋缁戝湪涓€璧枫€?/p>

瀵硅繖鏃犲ご Service 骞朵笉浼氬垎閰?Cluster IP锛宬ube-proxy 涓嶄細澶勭悊瀹冧滑锛?鑰屼笖骞冲彴涔熶笉浼氫负瀹冧滑杩涜璐熻浇鍧囪 鍜岃矾鐢便€?DNS 濡備綍瀹炵幇鑷姩閰嶇疆锛屼緷璧栦簬 Service 鏄惁瀹氫箟浜嗛€夋嫨绠楃銆?/p>

Nacos

有状态软件如何在 k8s 上快速扩容甚至自动扩容,第2张
nacos

馃敄 澶囨敞:

鏈夌姸鎬佹墿瀹圭浜屽眰:

StatefulSet + Headless Service + Init Container(鑷姩鍖栧彂鐜? + PVC

鐩告瘮 Eureka, nacos 閫氳繃涓€涓?code>init container,(杩欎釜 init container, 灏辨槸涓€涓嚜鍔ㄥ寲鐨?peer discovery 鑴氭湰.) , 瀹炵幇浜嗕竴琛屽懡浠ゅ揩閫熸墿瀹?

kubectl scale sts nacos --replicas=3

鑴氭湰閾炬帴涓? https://github.com/nacos-group/nacos-k8s/tree/master/plugin/peer

鎵╁鐨勭浉鍏宠嚜鍔ㄥ寲鎿嶄綔涓?

  1. 浠?Headless Service 鑷姩鍙戠幇鎵€鏈夌殑 replicas 鐨?HOSTNAME;
  2. 骞跺皢 HOSTNAME 鍐欏叆鍒? ${CLUSTER_CONF} 杩欎釜鏂囦欢涓?
  3. ${CLUSTER_CONF}杩欎釜鏂囦欢灏辨槸 nacos 闆嗙兢鐨勬墍鏈?member 淇℃伅. 灏嗘柊鍐欏叆 HOSTNAME 鐨勫疄渚嬪姞鍏ュ埌 nacos 闆嗙兢涓?

鍦ㄨ繖閲? 閫氳繃 Headless Service 鍜?PV/PVC(瀛樺偍 nacos 鎻掍欢鎴栧叾浠栨暟鎹?锛屽疄鐜颁簡瀵?Pod 鐨勬嫇鎵戠姸鎬佸拰瀛樺偍鐘舵€佺殑缁存姢锛屼粠鑰岃鐢ㄦ埛鍙互鍦?Kubernetes 涓婅繍琛屾湁鐘舵€佺殑搴旂敤銆?/p>

鐒惰€?Statefullset 鍙兘鎻愪緵鍙楅檺鐨勭鐞嗭紝閫氳繃 StatefulSet 鎴戜滑杩樻槸闇€瑕佺紪鍐欏鏉傜殑鑴氭湰(濡?nacos 鐨?code>peer-finder鐩稿叧鑴氭湰), 閫氳繃鍒ゆ柇鑺傜偣缂栧彿鏉ュ尯鍒妭鐐圭殑鍏崇郴鍜屾嫇鎵戯紝闇€瑕佸叧蹇冨叿浣撶殑閮ㄧ讲宸ヤ綔銆?/p>

RabbitMQ

有状态软件如何在 k8s 上快速扩容甚至自动扩容,第3张
rabbitmq

馃敄 澶囨敞:

鏈夌姸鎬佹墿瀹圭涓夊眰:

StatefulSet + Headless Service + 鎻掍欢(鑷姩鍖栧彂鐜板拰鐩戞帶) + PVC

RabbitMQ 鐨勯泦缇ゅ彲浠ュ弬鑰冭繖杈瑰畼鏂规枃妗? Cluster Formation and Peer Discovery

杩欓噷鎻愬埌鐨? 鍔ㄦ€佺殑鍙戠幇鏈哄埗闇€瑕佷緷璧栧閮ㄧ殑鏈嶅姟, 濡? DNS, API(AWS 鎴?K8S).

瀵逛簬 Kubernetes, 浣跨敤鐨勫姩鎬佸彂鐜版満鍒舵槸鍩轰簬rabbitmq-peer-discovery-k8s鎻掍欢 瀹炵幇鐨?

閫氳繃杩欑鏈哄埗锛岃妭鐐瑰彲浠ヤ娇鐢ㄤ竴缁勯厤缃殑鍊间粠 Kubernetes API 绔偣鑾峰彇鍏跺绛夋柟鐨勫垪琛細URI 妯″紡锛屼富鏈猴紝绔彛浠ュ強浠ょ墝鍜岃瘉涔﹁矾寰勩€?/p>

鍙﹀, rabbitmq 闀滃儚涔熼粯璁ら泦鎴愪簡鐩戞帶鐨勬彃浠?- rabbitmq_prometheus.

褰撶劧, 閫氳繃Helm Chart涔熻兘涓€閿儴缃插拰鎵╁.

Helm Chart

涓€鍙ヨ瘽姒傛嫭, Helm 涔嬩簬 Kubernetes, 鐩稿綋浜?yum 涔嬩簬 centos. 瑙e喅浜嗕緷璧栫殑闂. 灏嗛儴缃?rabbitmq 杩欎箞澶嶆潅鐨勮蒋浠舵墍闇€瑕佺殑涓€澶у爢 yaml, 閫氳繃鍙傛暟鍖栨娊璞″嚭蹇呰鐨勫弬鏁?骞朵笖鎻愪緵榛樿鍙傛暟)鏉ュ揩閫熼儴缃?

Redis

有状态软件如何在 k8s 上快速扩容甚至自动扩容,第4张
redis

馃敄 澶囨敞:

鏈夌姸鎬佹墿瀹圭鍥涘眰:

閫氳繃 Operator 缁熶竴缂栨帓鍜岀鐞?

Deployment(鍝ㄥ叺) + StatefulSet + Headless Service + Sidecar Container(鐩戞帶) + PVC

杩欓噷浠?UCloud 寮€婧愮殑: redis-operator 涓轰緥. 瀹冩槸鍩轰簬 鍝ㄥ叺妯″紡 鐨?redis 闆嗙兢.

浜庝箣鍓嶇殑 StatefulSet + Headless 涓嶅悓, 杩欓噷鐢ㄥ埌浜嗕竴椤规柊鐨?K8S 鎶€鏈? operator.

Operator 鍘熺悊

馃摉 璇存槑:

瑙i噴 Operator 涓嶅緱涓嶆彁 Kubernetes 涓袱涓渶鍏蜂环鍊肩殑鐞嗗康锛氣€滃0鏄庡紡 API鈥?鍜?鈥滄帶鍒跺櫒妯″紡鈥濄€傗€滃0鏄庡紡 API鈥濈殑鏍稿績鍘熺悊灏辨槸褰撶敤鎴峰悜 Kubernetes 鎻愪氦浜嗕竴涓?API 瀵硅薄鐨勬弿杩颁箣鍚庯紝Kubernetes 浼氳礋璐d负浣犱繚璇佹暣涓泦缇ら噷鍚勯」璧勬簮鐨勭姸鎬侊紝閮戒笌浣犵殑 API 瀵硅薄鎻忚堪鐨勯渶姹傜浉涓€鑷淬€侹ubernetes 閫氳繃鍚姩涓€绉嶅彨鍋氣€滄帶鍒跺櫒妯″紡鈥濈殑鏃犻檺寰幆锛學ATCH 杩欎簺 API 瀵硅薄鐨勫彉鍖栵紝涓嶆柇妫€鏌ワ紝鐒跺悗璋冭皭锛屾渶鍚庣‘淇濇暣涓泦缇ょ殑鐘舵€佷笌杩欎釜 API 瀵硅薄鐨勬弿杩颁竴鑷淬€?/p>

姣斿 Kubernetes 鑷甫鐨勬帶鍒跺櫒锛欴eployment锛屽鏋滄垜浠兂鍦?Kubernetes 涓儴缃插弻鍓湰鐨?Nginx 鏈嶅姟锛岄偅涔堟垜浠氨瀹氫箟涓€涓?repicas 涓?2 鐨?Deployment 瀵硅薄锛孌eployment 鎺у埗鍣?WATCH 鍒版垜浠殑瀵硅薄鍚庯紝閫氳繃鎺у埗寰幆锛屾渶缁堜細甯垜浠湪 Kubernetes 鍚姩涓や釜 Pod銆?/p>

Operator 鏄悓鏍风殑閬撶悊锛屼互鎴戜滑鐨?Redis Operator 涓轰緥锛屼负浜嗗疄鐜?Operator锛屾垜浠鍏堥渶瑕佸皢鑷畾涔夊璞$殑璇存槑娉ㄥ唽鍒?Kubernetes 涓紝杩欎釜瀵硅薄鐨勮鏄庡氨鍙?CustomResourceDefinition锛圕RD锛夛紝瀹冪敤浜庢弿杩版垜浠?Operator 鎺у埗鐨勫簲鐢細redis 闆嗙兢锛岃繖涓€姝ユ槸涓轰簡璁?Kubernetes 鑳藉璁よ瘑鎴戜滑搴旂敤銆傜劧鍚庨渶瑕佸疄鐜拌嚜瀹氫箟鎺у埗鍣ㄥ幓 WATCH 鐢ㄦ埛鎻愪氦鐨?redis 闆嗙兢瀹炰緥锛岃繖鏍峰綋鐢ㄦ埛鍛婅瘔 Kubernetes 鎴戞兂瑕佷竴涓?redis 闆嗙兢瀹炰緥鍚庯紝Redis Operator 灏辫兘澶熼€氳繃鎺у埗寰幆鎵ц璋冭皭閫昏緫杈惧埌鐢ㄦ埛瀹氫箟鐘舵€併€?/p>

绠€鍗曡, operator 鍙互缈昏瘧涓? 杩愮淮浜猴紙鎿嶄綔鍛橈級 . 灏辨槸灏嗛珮绾у師鍘傝繍缁翠笓瀹跺骞寸殑缁忛獙, 娴撶缉涓轰竴涓? operator. 閭d箞, 鎴戜滑鎵€鏈夌殑 杩愮淮鎵撳伐浜?/strong> 灏变笉闇€瑕佸啀鑻﹀搱鍝堢殑"浠庨浂寮€濮嬫惌寤?xxx 闆嗙兢", 鑰屾槸閫氳繃杩欎釜鍙墿灞曘€佸彲閲嶅銆佹爣鍑嗗寲銆佺敋鑷冲叏鐢熷懡鍛ㄦ湡杩愮淮绠$悊鐨?code>operator銆?鏉ュ畬鎴愬鏉傝蒋浠剁殑瀹夎锛屾墿瀹癸紝鐩戞帶, 澶囦唤鐢氳嚦鏁呴殰鎭㈠銆?/p>

Redis Operator

浣跨敤 Redis Operator 鎴戜滑鍙互寰堟柟渚跨殑璧蜂竴涓摠鍏垫ā寮忕殑闆嗙兢锛岄泦缇ゅ彧鏈変竴涓?Master 鑺傜偣锛屽涓?Slave 鑺傜偣锛屽亣濡傛寚瀹?Redis 闆嗙兢鐨?size 涓?3锛岄偅涔?Redis Operator 灏变細甯垜浠惎鍔ㄤ竴涓?Master 鑺傜偣锛屼袱涓?Salve 鑺傜偣锛屽悓鏃跺惎鍔ㄤ笁涓?Sentinel 鑺傜偣鏉ョ鐞?Redis 闆嗙兢锛?/p>

有状态软件如何在 k8s 上快速扩容甚至自动扩容,第5张
redis operator 鍝ㄥ叺鏋舵瀯

Redis Operator 閫氳繃 Statefulset 绠$悊 Redis 鑺傜偣锛岄€氳繃 Deployment 鏉ョ鐞?Sentinel 鑺傜偣锛岃繖姣旂鐞嗚8 Pod 瑕佸鏄擄紝鑺傜渷瀹炵幇鎴愭湰銆傚悓鏃跺垱寤轰竴涓?Service 鎸囧悜鎵€鏈夌殑鍝ㄥ叺鑺傜偣锛岄€氳繃 Service 瀵瑰鎴风鎻愪緵鏌ヨ Master銆丼lave 鑺傜偣鐨勬湇鍔°€傛渶缁堬紝Redis Operator 鎺у埗寰幆浼氳皟璋愰泦缇ょ殑鐘舵€侊紝璁剧疆闆嗙兢鐨勬嫇鎵戯紝璁╂墍鏈夌殑 Sentinel 鐩戞帶鍚屼竴涓?Master 鑺傜偣锛岀洃鎺х浉鍚岀殑 Salve 鑺傜偣锛孯edis Operator 闄や簡浼?WATCH 瀹炰緥鐨勫垱寤恒€佹洿鏂般€佸垹闄や簨浠讹紝杩樹細瀹氭椂妫€娴嬪凡鏈夌殑闆嗙兢鐨勫仴搴风姸鎬侊紝瀹炴椂鎶婇泦缇ょ殑鐘舵€佽褰曞埌 spec.status.conditions 涓?

鍚屾椂, 杩樻彁渚涗簡蹇€熸寔涔呭寲, 鐩戞帶, 鑷姩鍖?redis 闆嗙兢閰嶇疆鐨勮兘鍔? 鍙渶涓€涓?yaml 鍗冲彲瀹炵幇:

apiVersion: redis.kun/v1beta1
kind: RedisCluster
metadata:
  name: redis
spec:
  config:  # redis闆嗙兢閰嶇疆
    maxmemory: 1gb
    maxmemory-policy: allkeys-lru
  password: sfdfghc56s  # redis瀵嗙爜閰嶇疆
  resources:  # redis璧勬簮閰嶇疆
    limits:
      cpu: '1'
      memory: 1536Mi
    requests:
      cpu: 250m
      memory: 1Gi
  size: 3  # redis鍓湰鏁伴厤缃?
  storage:  # 鎸佷箙鍖栧瓨鍌ㄩ厤缃?
    keepAfterDeletion: true
    persistentVolumeClaim:
      metadata:
        name: redis
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 5Gi
        storageClassName: nfs
        volumeMode: Filesystem
  sentinel:   # 鍝ㄥ叺閰嶇疆
    image: 'redis:5.0.4-alpine'     
  exporter:  # 鍚敤鐩戞帶
    enabled: true 

瑕佹墿瀹逛篃寰堢畝鍗? 灏嗕笂杈圭殑size: 3鎸夐渶璋冩暣鍗冲彲. 璋冩暣鍚? 鑷姩鐢宠璧勬簮, 鎵╁, 鍔犲瓨鍌? 鏀?redis 閰嶇疆, 鍔犲叆 redis 闆嗙兢, 骞朵笖鑷姩娣诲姞鐩戞帶.

Kafka

有状态软件如何在 k8s 上快速扩容甚至自动扩容,第6张
strimzi

馃敄 澶囨敞:

鏈夌姸鎬佹墿瀹圭浜斿眰:

閫氳繃 Operator 缁熶竴缂栨帓鍜岀鐞嗗涓湁鐘舵€佺粍浠剁殑:

StatefulSet + Headless Service + ... + 鐩戞帶

杩欓噷浠?Strimzi 涓轰緥 - Strimzi Overview guide (0.20.0). 杩欐槸涓€涓?Kafka 鐨?Operator.

鎻愪緵浜?Apache Kafka 缁勪欢浠ラ€氳繃 Strimzi 鍙戣鐗堥儴缃插埌 Kubernetes銆?Kafka 缁勪欢閫氬父浠ラ泦缇ょ殑褰㈠紡杩愯浠ユ彁楂樺彲鐢ㄦ€с€?/p>

鍖呭惈 Kafka 缁勪欢鐨勫吀鍨嬮儴缃插彲鑳藉寘鎷細

  • Kafka 浠g悊鑺傜偣闆嗙兢闆嗙兢
  • ZooKeeper - ZooKeeper 瀹炰緥鐨勯泦缇?/li>
  • Kafka Connect 闆嗙兢鐢ㄤ簬澶栭儴鏁版嵁杩炴帴
  • Kafka MirrorMaker 闆嗙兢鍙湪绗簩涓泦缇や腑闀滃儚 Kafka 闆嗙兢
  • Kafka Exporter 鎻愬彇鍏朵粬 Kafka 鎸囨爣鏁版嵁浠ヨ繘琛岀洃鎺?/li>
  • Kafka Bridge 鍚?Kafka 闆嗙兢鍙戝嚭鍩轰簬 HTTP 鐨勮姹?/li>

Kafka 鐨勭粍浠舵灦鏋勬瘮杈冨鏉? 鍏蜂綋濡備笅:

有状态软件如何在 k8s 上快速扩容甚至自动扩容,第7张
img

閫氳繃 Operator, 涓€涓?YAML 鍗冲彲瀹屾垚涓€濂楀鏉傜殑閮ㄧ讲:

  • 璧勬簮璇锋眰锛圕PU /鍐呭瓨锛?/li>
  • 鐢ㄤ簬鏈€澶у拰鏈€灏忓唴瀛樺垎閰嶇殑 JVM 閫夐」
  • Listeners 锛堝拰韬唤楠岃瘉锛?/li>
  • 璁よ瘉
  • 瀛樺偍
  • Rack awareness
  • 鐩戞帶鎸囨爣
apiVersion: kafka.strimzi.io/v1beta1
kind: Kafka
metadata:
  name: my-cluster
spec:
  kafka:
    replicas: 3
    version: 0.20.0
    resources:
      requests:
        memory: 64Gi
        cpu: "8"
      limits:
        memory: 64Gi
        cpu: "12"
    jvmOptions:
      -Xms: 8192m
      -Xmx: 8192m
    listeners:
      - name: plain
        port: 9092
        type: internal
        tls: false
        useServiceDnsDomain: true
      - name: tls
        port: 9093
        type: internal
        tls: true
        authentication:
          type: tls
      - name: external
        port: 9094
        type: route
        tls: true
        configuration:
          brokerCertChainAndKey:
            secretName: my-secret
            certificate: my-certificate.crt
            key: my-key.key
    authorization:
      type: simple
    config:
      auto.create.topics.enable: "false"
      offsets.topic.replication.factor: 3
      transaction.state.log.replication.factor: 3
      transaction.state.log.min.isr: 2
      ssl.cipher.suites: "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" (17)
      ssl.enabled.protocols: "TLSv1.2"
      ssl.protocol: "TLSv1.2"
    storage: 
      type: persistent-claim
      size: 10000Gi
    rack:
      topologyKey: topology.kubernetes.io/zone
    metrics:
      lowercaseOutputName: true
      rules:
      # Special cases and very specific rules
      - pattern : kafka.server<type=(.+), name=(.+), clientId=(.+), topic=(.+), partition=(.*)><>Value
        name: kafka_server__
        type: GAUGE
        labels:
          clientId: ""
          topic: ""
          partition: ""
        # ...
  zookeeper:
    replicas: 3
    resources:
      requests:
        memory: 8Gi
        cpu: "2"
      limits:
        memory: 8Gi
        cpu: "2"
    jvmOptions:
      -Xms: 4096m
      -Xmx: 4096m
    storage:
      type: persistent-claim
      size: 1000Gi
    metrics:
      # ...
  entityOperator:
    topicOperator:
      resources:
        requests:
          memory: 512Mi
          cpu: "1"
        limits:
          memory: 512Mi
          cpu: "1"
    userOperator:
      resources:
        requests:
          memory: 512Mi
          cpu: "1"
        limits:
          memory: 512Mi
          cpu: "1"
  kafkaExporter:
    # ...
  cruiseControl:
    # ...

褰撶劧, 鐢变簬 Kafka 鐨勭壒娈婃€? 濡傛灉瑕佸皢鏂板鐨?brokers 娣诲姞鍒扮幇鏈夐泦缇? 杩橀渶瑕侀噸鏂板垎鍖? 杩欓噷杈规秹鍙婄殑鏇村鎿嶄綔璇﹁: Scaling Clusters - Using Strimzi

TiDB

有状态软件如何在 k8s 上快速扩容甚至自动扩容,第8张
tidb

馃敄 澶囨敞:

鏈夌姸鎬佹墿瀹圭鍏眰:

閫氳繃 Operator 缁熶竴缂栨帓鍜岀鐞嗗涓湁鐘舵€佺粍浠剁殑:

StatefulSet + Headless Service + ... + 鐩戞帶 + TidbClusterAutoScaler(绫讳技 HPA 鐨勫疄鐜?

鐢氳嚦鑳藉仛鍒板浠藉拰鐏鹃毦鎭㈠.

TiDB 鏇磋繘涓€姝? 鍙互瀹炵幇 鏈夌姸鎬佸簲鐢ㄨ嚜鍔ㄦ墿瀹?/strong>.

鍏蜂綋瑙佽繖閲? Enable TidbCluster Auto-scaling | PingCAP Docs

Kubernetes 鎻愪緵浜?code>Horizontal Pod Autoscaler 锛岃繖鏄竴绉嶅熀浜?CPU 鍒╃敤鐜囩殑鍘熺敓 API銆?TiDB 4.0 鍩轰簬 Kubernetes锛屽疄鐜颁簡寮规€ц皟搴︽満鍒躲€?/p>

鍙渶瑕佸惎鐢ㄦ鍔熻兘鍗冲彲浣跨敤:

features:
  - AutoScaling=true

TiDB 瀹炵幇浜嗕竴涓?code>TidbClusterAutoScaler CR 瀵硅薄鐢ㄤ簬鎺у埗 TiDB 闆嗙兢涓嚜鍔ㄧ缉鏀剧殑琛屼负銆?濡傛灉鎮ㄤ娇鐢ㄨ繃Horizontal Pod Autoscaler 锛屽ぇ姒傛槸鎮ㄧ啛鎮?TidbClusterAutoScaler 姒傚康銆?浠ヤ笅鏄?TiKV 涓殑鑷姩缂╂斁绀轰緥銆?/p>

apiVersion: pingcap.com/v1alpha1
kind: TidbClusterAutoScaler
metadata:
  name: auto-scaling-demo
spec:
  cluster:
    name: auto-scaling-demo
    namespace: default
  monitor:
    name: auto-scaling-demo
    namespace: default
  tikv:
    minReplicas: 3
    maxReplicas: 4
    metrics:
      - type: "Resource"
        resource:
          name: "cpu"
          target:
            type: "Utilization"
            averageUtilization: 80

闇€瑕佹寚鍑虹殑鏄? 闇€瑕佸悜TidbClusterAutoScaler 鎻愪緵鎸囨爣鏀堕泦鍜屾煡璇?鐩戞帶)鏈嶅姟锛屽洜涓哄畠閫氳繃鎸囨爣鏀堕泦缁勪欢鎹曡幏璧勬簮浣跨敤鎯呭喌銆?monitor 灞炴€у紩鐢?code>TidbMonitor 瀵硅薄(鍏跺疄灏辨槸鑷姩鍖栧湴閰嶇疆 TiDB 鐨?prometheus 鐩戞帶鍜屽睍绀虹瓑)銆?鏈夊叧鏇村淇℃伅锛岃鍙傝浣跨敤TidbMonitor鐩戣TiDB缇ら泦銆?/p>

鎬荤粨

閫氳繃 6 涓湁鐘舵€佽蒋浠? 鎴戜滑瑙佽瘑鍒颁簡灞傚眰閫掕繘鐨?K8S 涓婃湁鐘舵€佸簲鐢ㄧ殑蹇€熸墿瀹圭敋鑷虫槸鑷姩鎵╁:

  1. 鏈€绠€鍗曞疄鐜? StatefulSet + Headless Service -- Eureka
  2. 鑴氭湰/Init Container 鑷姩鍖栧疄鐜? StatefulSet + Headless Service + Init Container(鑷姩鍖栧彂鐜? + PVC -- Nacos
  3. 閫氳繃鎻掍欢瀹炵幇鎵╁鍜岀洃鎺?StatefulSet + Headless Service + 鎻掍欢(鑷姩鍖栧彂鐜板拰鐩戞帶) + PVC -- RabbitMQ
  4. 閫氳繃 Operator 缁熶竴缂栨帓鍜岀鐞? -- Redis
  5. 瀵逛簬澶嶆潅鏈夌姸鎬? 鏄渶瑕侀€氳繃 Operator 缁熶竴缂栨帓鍜岀鐞嗗涓湁鐘舵€佺粍浠剁殑: -- Kafka
  6. 閫氳繃 Operator 缁熶竴缂栨帓鍜岀鐞嗗涓湁鐘舵€佺粍浠剁殑: -- TiDB

馃槀馃槀馃槀 瑙f斁寮€鍙戝拰杩愮淮鎵撳伐浜?/strong>, 鏄椂鍊欏湪 K8S 涓婇儴缃叉湁鐘舵€佽蒋浠朵簡! 馃挭馃挭馃挭

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


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

相关文章: