K8s瀹e竷寮冪敤Docker锛屽崈涓囧埆鎱岋紒
Posted 51CTO鎶€鏈爤
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了K8s瀹e竷寮冪敤Docker锛屽崈涓囧埆鎱岋紒相关的知识,希望对你有一定的参考价值。
馃憞鎵爜绔嬪埢鍏虫敞馃憞
涓撴敞寮€婧愭妧鏈紝鍏卞缓楦胯挋鐢熸€?/span>
杩戞棩锛孠ubernetes 瀹樻柟鍙戝竷鍏憡锛屽甯冭嚜 v1.20 璧锋斁寮冨 Docker 鐨勬敮鎸侊紝灞婃椂鐢ㄦ埛灏嗘敹鍒?Docker 寮冪敤璀﹀憡锛屽苟闇€瑕佹敼鐢ㄥ叾浠栧鍣ㄨ繍琛屾椂銆?/span>
鍥剧墖鏉ヨ嚜 Pexels
浣?Docker 浣滀负瀹瑰櫒闀滃儚鏋勫缓宸ュ叿鐨勪綔鐢ㄥ皢涓嶅彈褰卞搷锛岀敤鍏舵瀯寤虹殑瀹瑰櫒闀滃儚灏嗕竴濡傛棦寰€鍦板湪闆嗙兢涓笌鎵€鏈夊鍣ㄨ繍琛屾椂姝e父杩愯浆銆?br>
Kubernetes 灏嗗純鐢?Docker
娌¢敊锛岃繖鏄湡鐨勶紝Kubernetes 鐜板凡寮冪敤 Docker锛?/span>
https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.20.md#deprecation
鐩墠锛孠ubelet 涓殑 Docker 鏀寔鍔熻兘鐜板凡寮冪敤锛屽苟灏嗗湪涔嬪悗鐨勭増鏈腑琚垹闄ゃ€?br>
Kubelet 涔嬪墠浣跨敤鐨勬槸涓€涓悕涓?dockershim 鐨勬ā鍧楋紝鐢ㄤ互瀹炵幇瀵?Docker 鐨?CRI 鏀寔銆?br>
绠€鑰岃█涔嬶紝Docker 骞朵笉鏀寔 CRI锛堝鍣ㄨ繍琛屾椂鎺ュ彛锛夎繖涓€ Kubernetes 杩愯鏃?API锛岃€?Kubernetes 鐢ㄦ埛涓€鐩翠互鏉ユ墍浣跨敤鐨勫叾瀹炴槸鍚嶄负鈥渄ockershim鈥濈殑妗ユ帴鏈嶅姟銆?br>
Dockershim 鑳藉杞崲 Docker API 涓?CRI锛屼絾鍦ㄥ悗缁増鏈綋涓紝Kubernetes 灏嗕笉鍐嶆彁渚涜繖椤规ˉ鎺ユ湇鍔°€?/span>
褰撶劧锛孌ocker 鏈韩涔熸槸涓€娆鹃潪甯稿己澶х殑宸ュ叿锛屽彲鐢ㄤ簬鍒涘缓寮€鍙戠幆澧冦€備絾涓轰簡浜嗚В閫犳垚褰撳墠鐘跺喌鐨勫師鍥狅紝鎴戜滑闇€瑕佸叏闈㈠垎鏋?Docker 鍦ㄧ幇鏈?Kubernetes 鏋舵瀯涓殑浣滅敤銆?/span>
Kubernetes 鏄竴娆惧熀纭€璁炬柦宸ュ叿锛屽彲瀵瑰绉嶄笉鍚岃绠楄祫婧愶紙渚嬪铏氭嫙/鐗╃悊鏈猴級杩涜鍒嗙粍锛屼娇鍏跺憟鐜颁负缁熶竴鐨勫法閲忚绠楄祫婧愶紝浠庤€屼緵搴旂敤绋嬪簭浣跨敤鎴栦笌鍏朵粬浜哄叡浜€?br>
閫氳繃浠ヤ笂鏋舵瀯鍥撅紝鍙互鐪嬪埌姣忎釜 Kubernetes 鑺傜偣閮戒笌鎺у埗骞抽潰褰兼閫氫俊銆傚悇涓妭鐐逛笂鐨?kubelet 鑾峰彇鍏冩暟鎹紝骞舵墽琛?CRI 浠ュ湪璇ヨ妭鐐逛笂杩愯瀹瑰櫒鐨勫垱寤?鍒犻櫎銆?/span>
Docker 涓轰粈涔堜細琚純鐢紵
濡傚墠鎵€杩帮紝Kubernetes 鍙兘涓?CRI 閫氫俊锛屽洜姝よ涓?Docker 閫氫俊锛屽氨蹇呴』浣跨敤妗ユ帴鏈嶅姟銆傝繖灏辨槸绗竴鐐瑰師鍥犮€?/span>
娌¢敊锛孠ubernetes 瀹為檯涓婇渶瑕佷繚鎸佸湪绾㈡涔嬪唴銆侱ocker 缃戠粶涓庡瓨鍌ㄥ嵎閮借鎺掗櫎鍦ㄥ銆?/span>
鑰岃繖浜涚敤涓嶅埌鐨勫姛鑳芥湰韬氨鍙兘甯︽潵瀹夊叏闅愭偅銆備簨瀹炰笂锛屼綘鎷ユ湁鐨勫姛鑳借秺灏戯紝鏀诲嚮闈篃灏辫秺灏忋€傚洜姝わ紝鎴戜滑闇€瑕佽€冭檻浣跨敤鏇夸唬鏂规锛屽嵆 CRI 杩愯鏃躲€?/span>
CRI 杩愯鏃剁殑瀹炵幇鏂规涓昏鏈変袱绉嶏細
鈶燾ontainerd
濡傛灉澶у鍙槸鎯充粠 Docker 杩佺Щ鍑烘潵锛岄偅涔?containerd 灏辨槸鏈€濂界殑閫夋嫨銆傚洜涓哄畠瀹為檯涓婂氨鏄湪 Docker 涔嬪唴璧锋晥锛屽彲浠ュ畬鎴愭墍鏈夆€滆繍琛屾椂鈥濆伐浣滐紝濡備笂鍥炬墍绀恒€傛洿閲嶈鐨勬槸锛屽畠鎻愪緵鐨?CRI 鍏跺疄 100% 灏辨槸鐢?Docker 鎵€鎻愪緵銆?/span>
https://github.com/containerd/containerd/
鈶RI-O
CRI-O 鏄富瑕佺敱 Red Hat 鍛樺伐寮€鍙戠殑 CRI 杩愯鏃躲€傚畠鐨勬渶澶у尯鍒湪浜庡苟涓嶄緷璧栦簬 Docker锛岃€屼笖鐩墠宸茬粡鍦?Red Hat OpenShift 涓緱鍒颁娇鐢ㄣ€?/span>
https://github.com/cri-o/cri-o
CRI-O 鐨勪紭鍔垮湪浜庡叾閲囩敤鏋佺畝椋庢牸锛屾垨鑰呰瀹冪殑璁捐鏈韩灏辨槸浣滀负鈥淐RI鈥濊繍琛屾椂瀛樺湪銆?br>
涓嶅悓浜庝綔涓?Docker 缁勬垚閮ㄥ垎鐨?containerd锛孋RI-O 鍦ㄦ湰璐ㄤ笂灞炰簬绾?CRI 杩愯鏃躲€佸洜姝や笉鍖呭惈闄?CRI 涔嬪鐨勪换浣曞叾浠栧唴瀹广€?/span>
浠?Docker 杩佺Щ鑷?CRI-O 寰€寰€鏇翠负鍥伴毦锛屼絾鏃犺濡備綍锛孋RI-O 鑷冲皯鍙互鏀寔 Docker 瀹瑰櫒鍦?Kubernetes 涓婄殑姝e父杩愯銆?/span>
杩樻湁涓€鐐癸紝褰撴垜浠皥璁哄鍣ㄨ繍琛屾椂鏃讹紝璇锋敞鎰忔垜浠埌搴曟槸鍦ㄨ皥璁哄摢绉嶇被鍨嬬殑杩愯鏃躲€?br>
杩愯鏃跺垎涓轰袱绉嶏細
CRI 杩愯鏃?br>
-
OCI 杩愯鏃?/span>
CRI 杩愯鏃?/strong>
姝e涔嬪墠鎵€鎻愬埌锛孋RI 鏄?Kubernetes 鎻愪緵鐨?API锛岀敤浜庡悓瀹瑰櫒杩愯鏃惰繘琛岄€氫俊浠ュ垱寤?鍒犻櫎瀹瑰櫒鍖栧簲鐢ㄧ▼搴忋€?/span>
鍚勫鍣ㄥ寲搴旂敤绋嬪簭浣滀负 kubelet 閫氳繃 IPC 鍦?gRPC 鍐呴€氫俊锛岃€屼笖杩愯鏃朵篃杩愯鍦ㄥ悓涓€涓绘満涔嬩笂锛汣RI 杩愯鏃惰礋璐d粠 kubelet 鑾峰彇璇锋眰骞舵墽琛?OCI 瀹瑰櫒杩愯鏃朵互杩愯瀹瑰櫒銆?br>
绋嶅井鏈夌偣澶嶆潅锛屾帴涓嬫潵鎴戜滑浼氱敤鍥捐〃鏉ヨВ閲婏細
鍥犳锛孋RI 杩愯鏃跺皢鎵ц浠ヤ笅鎿嶄綔锛?/span>
浠?kubelet 鑾峰彇 gRPC 璇锋眰銆?/span>
鏍规嵁瑙勮寖鍒涘缓 OCI json 閰嶇疆銆?/span>
OCI 杩愯鏃?/strong>
OCI 杩愯鏃惰礋璐d娇鐢?Linux 鍐呮牳绯荤粺璋冪敤锛堜緥濡?cgroups 涓庡懡鍚嶇┖闂达級鐢熸垚瀹瑰櫒銆備綘鍙兘鍚杩?runC 鎴栬€?gVisor锛岃繖灏辨槸浜嗐€?/span>
杩欎篃鎰忓懗鐫€锛屽鏋滀綘鍙戠幇 runC 涓殑婕忔礊浼氫娇浣犺幏寰椾富鏈?root 鏉冮檺锛岄偅涔堝鍣ㄥ寲搴旂敤绋嬪簭鍚屾牱浼氶€犳垚 root 鏉冮檺澶栨硠銆?/span>
鏈夎叮鐨勬槸锛実Visor 涓寘鍚竴涓€滆瀹㈠唴鏍糕€濆眰锛屾剰鍛崇潃瀹瑰櫒鍖栧簲鐢ㄧ▼搴忔棤娉曠洿鎺ユ帴瑙﹀埌涓绘満鍐呮牳灞傘€?br>
鍗充娇鏄簲鐢ㄧ▼搴忊€滆涓衡€濊嚜宸辨帴瑙﹀埌浜嗭紝瀹為檯鎺ヨЕ鍒扮殑涔熷彧鏄?gVisor 鐨勮瀹㈠唴鏍搞€?br>
https://gvisor.dev/docs/
鎬ц兘鏇村樊
-
Linux鍐呮牳灞傚苟闈?100% 鍏煎锛屽弬瑙佸畼鏂规枃妗d腑鐨勫吋瀹规€ч儴鍒嗭細
https://gvisor.dev/docs/user_guide/compatibility/
涓嶅彈榛樿鏀寔
Docker 纭寮冪敤锛屽ぇ瀹跺簲璇ュ紑濮嬭€冭檻浣跨敤 CRI 杩愯鏃讹紝渚嬪 containerd 涓?CRI-O銆俢ontainerd 涓?Docker 鐩稿吋瀹癸紝浜岃€呭叡浜浉鍚岀殑鏍稿績缁勪欢銆傚鏋滀綘涓昏浣跨敤 Kubernetes 鐨勬渶浣庡姛鑳介€夐」锛孋RI-O 鍙兘鏇翠负閫傚悎銆?/span>
鏄庣‘鐞嗚В CRI 杩愯鏃朵笌 OCI 杩愯鏃朵箣闂寸殑鍔熻兘涓庝綔鐢ㄨ寖鍥村樊寮傘€?/span>
鏍规嵁浣犵殑瀹為檯宸ヤ綔璐熻浇涓庝笟鍔¢渶姹傦紝runC鍙兘骞朵笉鎬绘槸鏈€濂界殑閫夋嫨锛岃閰屾儏鍋氬嚭鑰冮噺锛?br>
搴熷純 Docker锛屼絾鍒厡锛?/p>
瀵逛簬 Kubernetes 鏈€缁堢敤鎴凤紝姝ゆ璋冩暣鍚屾牱涓嶄細鏈夊お澶у奖鍝嶃€侱ocker 涓嶄細灏辨娑堜骸锛屼綘涔熶粛鐒跺彲浠ョ户缁皢 Docker 浣滀负寮€鍙戝伐鍏蜂娇鐢ㄣ€?br>
Docker 浼氱户缁瀯寤鸿捣涓嶈鍏舵暟鐨勫鍣紝鑰岃繍琛?docker build 鍛戒护鎵€鐢熸垚鐨勯暅鍍忎粛鍙湪 Kubernetes 闆嗙兢鍐呮甯歌繍琛屻€?br>
濡傛灉浣犱娇鐢ㄧ殑鏄?GKE 鎴栬€?EKS 绛夋墭绠?Kubernetes 鏈嶅姟锛屽垯闇€瑕佺‘淇濆湪鏈潵鐨?Kubernetes 鐗堟湰褰诲簳鍘婚櫎 Docker 鏀寔涔嬪墠锛屼负浣犵殑宸ヤ綔鑺傜偣寮曞叆鍙楁敮鎸佺殑瀹瑰櫒杩愯鏃躲€?br>
濡傛灉鑺傜偣涓寘鍚嚜瀹氫箟椤癸紝浣犲彲鑳介渶瑕佹牴鎹綋鍓嶇幆澧冨強杩愯鏃惰姹傚仛鍑烘洿鏂般€傝涓庢湇鍔′緵搴斿晢鍚堜綔锛岀‘淇濇纭畬鎴愬崌绾ф祴璇曞強瑙勫垝銆?br>
濡傛灉浣犵殑闆嗙兢涓€鐩村湪婊氬姩鎵╁睍锛屽垯闇€瑕侀厤鍚堝彉閲忎互閬垮厤鏈嶅姟涓柇銆傚湪 1.20 鐗堟湰涓紝浣犲皢鏀跺埌 Docker 寮冪敤璀﹀憡銆?br>
鑰屽湪鏈潵鐨?Kubernets 鐗堟湰锛堣鍒掑湪 2021 骞翠笅鍗婂勾鍙戝竷鐨?1.23 鐗堟湰锛変腑锛孌ocker 杩愯鏃跺皢琚交搴曠Щ闄ゃ€佷笉鍐嶅彈鍒版敮鎸侊紝灞婃椂鎮ㄥ繀椤诲垏鎹㈣嚦鍏朵粬鍏煎鐨勫鍣ㄨ繍琛屾椂锛屼緥濡?containerd 鎴栬€?CRI-O銆?br>
鍙渶瑕佷繚璇佷綘鎵€閫夊畾鐨勮繍琛屾椂锛岃兘澶熸敮鎸佸綋鍓嶄娇鐢ㄧ殑 Docker 瀹堟姢绋嬪簭閰嶇疆鍗冲彲锛堜緥濡傛棩蹇楄褰曪級銆?br>
鏃㈢劧闂涓嶅ぇ锛屽ぇ瀹跺湪鎱屼粈涔堬紵鍦ㄦ€曚粈涔堬紵
杩欓噷鎴戜滑闇€瑕佹帰璁ㄤ袱绉嶄笉鍚岀殑鐜锛岃€岃繖涔熸槸鎭愭厡鎯呯华鐨勬牴婧愩€傞鍏堬紝鍦?Kubernetes 闆嗙兢鍐呴儴瀛樺湪涓€绉嶅彨浣滃鍣ㄨ繍琛屾椂鐨勪笢瑗匡紝璐熻矗鎻愬彇骞惰繍琛屽鍣ㄩ暅鍍忋€?br>
Docker 鏄洰鍓嶆渶娴佽鐨勮繍琛屾椂閫夐」锛堝叾浠栧父瑙侀€夐」杩樺寘鎷?containerd 涓?CRI-O锛夈€?br>
浣?Docker 鍦ㄨ璁′笂骞舵湭鑰冭檻鍒拌宓屽叆 Kubernetes 杩欑鐢ㄦ硶锛屾墍浠ュ彲鑳藉紩鍙戦棶棰樸€?br>
寰堟槑鏄撅紝杩欓噷鎴戜滑鎻愬埌鐨勨€淒ocker鈥濆苟涓嶆槸鍚屼竴绉嶄笢瑗库€斺€斿畠浠h〃鐫€涓€鏁村鎶€鏈爤锛岃€?containerd 楂樼骇瀹瑰櫒杩愯鏃跺垯鏄?Docker 涓殑涓€閮ㄥ垎銆?br>
Docker 寰堥叿銆佸疄鐢ㄦ€ф瀬寮猴紝鎻愪緵澶氱鐢ㄦ埛浣撻獙澧炲己鍔熻兘锛岃鎴戜滑鑳藉鍦ㄥ紑鍙戣繃绋嬩腑杞绘澗瀹屾垚鍗忓悓浜や簰銆?br>
浣嗘槸锛岀敤鎴蜂綋楠屽寮哄姛鑳藉 Kubernetes 鏉ヨ骞堕潪蹇呴渶锛屽洜涓?Kubernetes 骞朵笉鏄粈涔堜汉绫诲崗浣滄柟銆?br>
缁撴灉灏辨槸锛岃鎯宠 containerd 杩欎釜浜虹被鍙嬪ソ鍨嬫娊璞″眰鍙戞尌浣滅敤锛孠ubernetes 闆嗙兢灏卞繀椤诲紩鍏ュ彟涓€娆惧悕涓?Dockershimi 鐨勫伐鍏枫€?br>
浣嗚繖娆惧伐鍏风殑浠嬪叆鍙堝紩鍙戜簡鏂扮殑闂锛屽洜涓烘垜浠繀椤婚澶栧姞浠ョ淮鎶わ紝鍚﹀垯灏卞彲鑳藉紩鍙戝畨鍏ㄩ棶棰樸€?br>
浜嬪疄涓婏紝Dockershim 鏃╁湪 Kubelet 1.23 鐗堟湰鏃跺氨宸茬粡琚Щ闄わ紝鎴栬€呰 Kubelet 寰堟棭灏卞彇娑堜簡灏?Docker 浣滀负瀹瑰櫒杩愯鏃剁殑鍔熻兘銆?br>
杩欐椂鍊欏緢澶氭湅鍙嬪彲鑳借闂紝鏃㈢劧 Docker 鏍堜腑宸茬粡鍖呭惈 containerd锛孠ubernetes 涓轰粈涔堣繕瑕佺敾铔囨坊瓒冲湴鎼炲嚭涓?Dockershim锛?br>
杩欐槸鍥犱负 Docker 涓?CRI锛堝嵆瀹瑰櫒杩愯鏃舵帴鍙o級骞朵笉鐩稿銆傛鏄洜涓轰笉鐩稿锛屾墍浠ユ垜浠墠闇€瑕?Dockershim 鏉ョ紦鍐蹭竴涓嬨€?br>
浣嗚繖涓嶆槸浠€涔堝ぇ闂锛屽悇浣嶆病蹇呰鎯婃厡锛佽繖浠朵簨鐨勬湰璐紝灏辨槸鎶婂鍣ㄨ繍琛屾椂浠?Docker 杞崲涓哄彟涓€绉嶅彈鏀寔鐨勯€夐」銆?br>
杩欓噷闇€瑕佹敞鎰忕殑鏄細濡傛灉澶у灏嗗簳灞?Docker 濂楁帴瀛楋紙/var/run/docker.sock锛夎瀹氫负闆嗙兢宸ヤ綔娴佷腑鐨勪竴閮ㄥ垎锛岄偅涔堣浆鎹㈣嚦鍏朵粬杩愯鏃朵細鐮村潖鎺夊綋鍓嶄笟鍔$殑姝e父杩愯銆?br>
杩欑妯″紡绉颁负 Docker in Docker锛屽ソ鍦ㄦ垜浠彲浠ヤ娇鐢ㄥ绉嶉€夐」瑙e喅杩欎釜鐗瑰畾鐢ㄤ緥锛屽寘鎷?Kaniko銆両mg 浠ュ強 Buildah 绛夌瓑銆?/span>
瀵瑰紑鍙戣€呮潵璇存剰鍛崇潃浠€涔堬紵
浣嗚繖绉嶅彉鍖栧寮€鍙戣€呮剰鍛崇潃浠€涔堬紵鎴戜滑杩橀渶瑕佺紪鍐?Dockerfiles 鍚楋紵鏈潵杩樺簲涓嶅簲璇ョ户缁娇鐢?Docker锛?br>
璇锋敞鎰忥紝鏈鍙樻洿鎵€褰卞搷鍒扮殑鐜锛屽叾瀹炶窡澶у鏁颁汉鐢ㄤ簬杩涜 Docker 浜や簰鐨勭幆澧冨苟涓嶆槸涓€鍥炰簨銆?/span>
浣犲湪寮€鍙戜腑浣跨敤鐨?Docker 瀹夎锛屼笌 Kubernetes 闆嗙兢涓殑 Docker 杩愯鏃舵鏃犲叧绯汇€傛垜鐭ラ亾锛岃繖浜嬪惉璧锋潵璁╀汉鏈夌偣鐘糠绯娿€?br>
鎬讳箣锛屽浜庡紑鍙戜汉鍛橈紝Docker 鍦ㄥ叕甯冩娆℃洿鏀逛箣鍓嶆彁渚涚殑鎵€鏈夋柟妗堥兘浠嶇劧閫傜敤銆?br>
Docker 鐢熸垚鐨勯暅鍍忓疄闄呬笂骞朵笉鐗瑰畾浜?Docker锛屾洿鍑嗙‘鍦拌瀹冨簲璇ュ睘浜?OCI锛堝紑鏀惧鍣ㄥ€¤锛夐暅鍍忋€?br>
浠讳綍涓?OCI 鐩稿吋瀹圭殑闀滃儚锛屾棤璁轰娇鐢ㄥ摢绉嶅伐鍏锋瀯寤鸿€屾垚锛屽浜?Kubernetes 鏉ヨ閮芥槸涓€鏍风殑銆?br>
Containerd 涓?CRI-O 閮借兘璇嗗埆杩欎簺闀滃儚骞舵甯歌繍琛岋紝杩欎篃鏄垜浠缓绔嬩竴濂楃粺涓€瀹瑰櫒鏍囧噯鐨勬剰涔夋墍鍦ㄣ€?/span>
鍥犳锛岃櫧鐒跺彉鍖栧嵆灏嗗埌鏉ワ紝铏界劧浼氱粰閮ㄥ垎鐢ㄦ埛甯︽潵楹荤儲锛屼絾褰卞搷骞朵笉绠楀ぇ銆傝€屼笖浠庨暱杩滆搴︾湅锛岃繖鍏跺疄鏄欢濂戒簨銆?br>
鎬昏€岃█涔嬶紝甯屾湜澶у鏀句笅鎶佃Е鍜屾亹鎱屾儏缁紝鍧︾劧鎺ュ彈杩欎釜鍙樺寲銆?/span>
鍙傝€冮摼鎺ワ細
https://kubernetes.io/blog/2020/12/02/dont-panic-kubernetes-and-docker/
https://dev.to/inductor/wait-docker-is-deprecated-in-kubernetes-now-what-do-i-do-e4m
绮惧僵鏂囩珷鎺ㄨ崘锛?/strong>
以上是关于K8s瀹e竷寮冪敤Docker锛屽崈涓囧埆鎱岋紒的主要内容,如果未能解决你的问题,请参考以下文章
寰俊api璋冪敤闄愬埗锛?5009 reach max api daily quota limit 瑙e喅鏂规硶