国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

研發(fā)工程師玩轉(zhuǎn)Kubernetes——使用Node特性定向調(diào)度Pod

這篇具有很好參考價值的文章主要介紹了研發(fā)工程師玩轉(zhuǎn)Kubernetes——使用Node特性定向調(diào)度Pod。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

在《研發(fā)工程師玩轉(zhuǎn)Kubernetes——使用污點(diǎn)(taint)驅(qū)逐Pod》中我們提到親和性(affinity)中的requiredDuringSchedulingIgnoredDuringExecution,它可以定向調(diào)度Pod。本節(jié)我們將使用相關(guān)特性完成定向調(diào)度的介紹。

nodeSelector定向調(diào)度

我們先模擬Pod被部署在Master Node上的場景。這個時候我們可以使用nodeSelector對Node的Labels做選擇。
首先我們查看當(dāng)前的Node的情況:

查看Node的Labels

get nodes --show-labels
NAME      STATUS   ROLES    AGE   VERSION   LABELS
ubuntuc   Ready    <none>   16m   v1.26.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=ubuntuc,kubernetes.io/os=linux,microk8s.io/cluster=true,node.kubernetes.io/microk8s-worker=microk8s-worker
ubuntue   Ready    <none>   15m   v1.26.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=ubuntue,kubernetes.io/os=linux,microk8s.io/cluster=true,node.kubernetes.io/microk8s-worker=microk8s-worker
ubuntud   Ready    <none>   15m   v1.26.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=ubuntud,kubernetes.io/os=linux,microk8s.io/cluster=true,node.kubernetes.io/microk8s-worker=microk8s-worker
ubuntub   Ready    <none>   16m   v1.26.4   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=ubuntub,kubernetes.io/os=linux,microk8s.io/cluster=true,node.kubernetes.io/microk8s-worker=microk8s-worker
ubuntua   Ready    <none>   20m   v1.27.2   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=ubuntua,kubernetes.io/os=linux,microk8s.io/cluster=true,node.kubernetes.io/microk8s-controlplane=microk8s-controlplane

可以看到只有Master Node(UbuntuA)的Labels含有node.kubernetes.io/microk8s-controlplane=microk8s-controlplane,我們就用這個去做條件選擇。

清單文件指定Label

# nginx_deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx-container
        image: nginx
        ports:
        - containerPort: 80
      nodeSelector:
        node.kubernetes.io/microk8s-controlplane: microk8s-controlplane

注意最后兩行,即使用nodeSelector讓Pod在Labels含有node.kubernetes.io/microk8s-controlplane: microk8s-controlplane的Node上部署。

NodeSelector map[string]string `json:"nodeSelector,omitempty"`

部署

針對上述文件部署Pod

kubectl create -f nginx_deployment.yaml

deployment.apps/nginx-deployment created

kubectl get pods -o wide
NAME                                READY   STATUS    RESTARTS   AGE   IP           NODE      NOMINATED NODE   READINESS GATES
nginx-deployment-5d5bc8fb96-75c9d   1/1     Running   0          67s   10.1.94.67   ubuntua   <none>           <none>

可以看到Pod被部署到Master Node上了。

requiredDuringSchedulingIgnoredDuringExecution定向調(diào)度

requiredDuringSchedulingIgnoredDuringExecution是親和性(affinity)下的一種類型,它表示:只有在規(guī)則被滿足的時候才能執(zhí)行調(diào)度。
我們修改下清單文件,讓Pod只能被調(diào)度到Master Node(UbuntuA)上。

清單文件指定親和性

# nginx_deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: node.kubernetes.io/microk8s-controlplane
                operator: In
                values:
                - microk8s-controlplane
      containers:
      - name: nginx-container
        image: nginx
        ports:
        - containerPort: 80

nodeSelectorTerms只能是一組matchExpressions。

type NodeAffinity struct {
	// If the affinity requirements specified by this field are not met at
	// scheduling time, the pod will not be scheduled onto the node.
	// If the affinity requirements specified by this field cease to be met
	// at some point during pod execution (e.g. due to a node label update),
	// the system will try to eventually evict the pod from its node.
	RequiredDuringSchedulingRequiredDuringExecution *NodeSelector  `json:"requiredDuringSchedulingRequiredDuringExecution,omitempty"`
	// If the affinity requirements specified by this field are not met at
	// scheduling time, the pod will not be scheduled onto the node.
	// If the affinity requirements specified by this field cease to be met
	// at some point during pod execution (e.g. due to a node label update),
	// the system may or may not try to eventually evict the pod from its node.
	RequiredDuringSchedulingIgnoredDuringExecution  *NodeSelector  `json:"requiredDuringSchedulingIgnoredDuringExecution,omitempty"`
	// The scheduler will prefer to schedule pods to nodes that satisfy
	// the affinity expressions specified by this field, but it may choose
	// a node that violates one or more of the expressions. The node that is
	// most preferred is the one with the greatest sum of weights, i.e.
	// for each node that meets all of the scheduling requirements (resource
	// request, RequiredDuringScheduling affinity expressions, etc.),
	// compute a sum by iterating through the elements of this field and adding
	// "weight" to the sum if the node matches the corresponding MatchExpressions; the
	// node(s) with the highest sum are the most preferred.
	PreferredDuringSchedulingIgnoredDuringExecution []PreferredSchedulingTerm  `json:"preferredDuringSchedulingIgnoredDuringExecution,omitempty"`
}

// A node selector represents the union of the results of one or more label queries
// over a set of nodes; that is, it represents the OR of the selectors represented
// by the nodeSelectorTerms.
type NodeSelector struct {
	// nodeSelectorTerms is a list of node selector terms. The terms are ORed.
	NodeSelectorTerms []NodeSelectorTerm `json:"nodeSelectorTerms,omitempty"`
}

// An empty node selector term matches all objects. A null node selector term
// matches no objects.
type NodeSelectorTerm struct {
	// matchExpressions is a list of node selector requirements. The requirements are ANDed.
	MatchExpressions []NodeSelectorRequirement `json:"matchExpressions,omitempty"`
}

// A node selector requirement is a selector that contains values, a key, and an operator
// that relates the key and values.
type NodeSelectorRequirement struct {
	// key is the label key that the selector applies to.
	Key string `json:"key" patchStrategy:"merge" patchMergeKey:"key"`
	// operator represents a key's relationship to a set of values.
	// Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt.
	Operator NodeSelectorOperator `json:"operator"`
	// values is an array of string values. If the operator is In or NotIn,
	// the values array must be non-empty. If the operator is Exists or DoesNotExist,
	// the values array must be empty. If the operator is Gt or Lt, the values
	// array must have a single element, which will be interpreted as an integer.
    // This array is replaced during a strategic merge patch.
	Values []string `json:"values,omitempty"`
}

// A node selector operator is the set of operators that can be used in
// a node selector requirement.
type NodeSelectorOperator string

const (
	NodeSelectorOpIn           NodeSelectorOperator = "In"
	NodeSelectorOpNotIn        NodeSelectorOperator = "NotIn"
	NodeSelectorOpExists       NodeSelectorOperator = "Exists"
	NodeSelectorOpDoesNotExist NodeSelectorOperator = "DoesNotExist"
	NodeSelectorOpGt           NodeSelectorOperator = "Gt"
	NodeSelectorOpLt           NodeSelectorOperator = "Lt"
)

觀察

get pod --watch -o wide
NAME                                READY   STATUS    RESTARTS   AGE   IP       NODE     NOMINATED NODE   READINESS GATES
nginx-deployment-549db84c68-gk66n   0/1     Pending             0          0s      <none>        <none>    <none>           <none>
nginx-deployment-549db84c68-gk66n   0/1     Pending             0          0s      <none>        ubuntua   <none>           <none>
nginx-deployment-549db84c68-gk66n   0/1     ContainerCreating   0          0s      <none>        ubuntua   <none>           <none>
nginx-deployment-549db84c68-gk66n   0/1     ContainerCreating   0          1s      <none>        ubuntua   <none>           <none>
nginx-deployment-549db84c68-gk66n   1/1     Running             0          4s      10.1.94.80    ubuntua   <none>           <none>

可以看到Pod是在Worker Node(UbuntuA)上部署著。文章來源地址http://www.zghlxwxcb.cn/news/detail-477565.html

參考資料

  • https://kubernetes.io/zh-cn/docs/concepts/scheduling-eviction/assign-pod-node/
  • https://github.com/kubernetes/design-proposals-archive/blob/main/scheduling/podaffinity.md

到了這里,關(guān)于研發(fā)工程師玩轉(zhuǎn)Kubernetes——使用Node特性定向調(diào)度Pod的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 研發(fā)工程師玩轉(zhuǎn)Kubernetes——啟動、存活和就緒探針

    研發(fā)工程師玩轉(zhuǎn)Kubernetes——啟動、存活和就緒探針

    啟動(Startup Probe)、存活(Liveness Probe)和就緒探針(Readiness Probe)有其不同的用途和優(yōu)先級。 啟動探針(Startup Probe)用于Pod內(nèi)程序告訴kubernetes,其準(zhǔn)備工作已經(jīng)做好。這些準(zhǔn)備工作主要是指業(yè)務(wù)運(yùn)行前的前置條件,比如資源文件下載完畢,內(nèi)置數(shù)據(jù)庫文件下載完畢等。這步

    2024年02月13日
    瀏覽(26)
  • 【個人介紹】后端研發(fā)工程師

    1. 熟悉JAVA基礎(chǔ)、多線程、并發(fā)編程、設(shè)計模式、數(shù)據(jù)結(jié)構(gòu)與算法、JVM原理與調(diào)優(yōu)等。 2. 熟悉SpringBoot、SpringCloud、SpringCloud Alibaba、JPA、MyBatis等框架。 3. 熟悉數(shù)據(jù)庫設(shè)計、MySQL原理與索引優(yōu)化、Redis、Memecache、MongoDB等。 4. 熟悉Nginx、主從集群、TCP/IP、NIO編程、Reactor模式、Nett

    2023年04月09日
    瀏覽(36)
  • 一些研發(fā)工程師在Springboot注意點(diǎn)

    一些研發(fā)工程師在Springboot注意點(diǎn)

    1. 正確設(shè)計代碼目錄結(jié)構(gòu) 雖然您有很大的自由度,但有一些基本規(guī)則值得遵循來設(shè)計您的源代碼結(jié)構(gòu)。 避免使用默認(rèn)包。確保所有內(nèi)容(包括入口點(diǎn))都在命名良好的包中,這樣您就可以避免與組裝和組件掃描相關(guān)的意外情況; 將 Application.java(應(yīng)用程序的入口類)放在頂

    2024年02月08日
    瀏覽(22)
  • 技術(shù)精英求職必備:大數(shù)據(jù)研發(fā)工程師簡歷模板

    原則 撰寫針對大數(shù)據(jù)研發(fā)工程師職位的簡歷時,關(guān)鍵在于準(zhǔn)確展現(xiàn)您在 大數(shù)據(jù)處理、分析和應(yīng)用開發(fā)方面的綜合技能、項(xiàng)目經(jīng)驗(yàn)和技術(shù)成就 。簡歷應(yīng)作為您展示跨多個技術(shù)棧的 編程能力、構(gòu)建完整大數(shù)據(jù)解決方案和有效解決大數(shù)據(jù)技術(shù)問題 的能力的窗口。確保每一項(xiàng)經(jīng)歷

    2024年02月21日
    瀏覽(25)
  • 《研發(fā)效能(DevOps)工程師》課程簡介(二)丨IDCF

    《研發(fā)效能(DevOps)工程師》課程簡介(二)丨IDCF

    為貫徹落實(shí)《關(guān)于深化人才發(fā)展體制機(jī)制改革的意見》,推動實(shí)施人才強(qiáng)國戰(zhàn)略,促進(jìn)專業(yè)技術(shù)人員提升職業(yè)素養(yǎng)、補(bǔ)充新知識新技能,實(shí)現(xiàn)人力資源深度開發(fā),推動經(jīng)濟(jì)社會全面發(fā)展,根據(jù)《中華人民共和國勞動法》有關(guān)規(guī)定,工業(yè)和信息化部教育與考試中心聯(lián)合有關(guān)部門

    2024年02月07日
    瀏覽(21)
  • 技術(shù)精英求職必備:AIGC(圖像生成)研發(fā)工程師簡歷指南

    核心原則 撰寫針對AIGC(圖像生成)研發(fā)工程師職位的簡歷時,關(guān)鍵在于準(zhǔn)確展現(xiàn)您在深度學(xué)習(xí)、計算機(jī)視覺和圖像生成算法方面的綜合技能、項(xiàng)目經(jīng)驗(yàn)和技術(shù)成就。簡歷應(yīng)作為您展示跨多個技術(shù)棧的編程能力、構(gòu)建完整的圖像生成解決方案和有效解決AIGC技術(shù)問題的能力的窗口

    2024年03月25日
    瀏覽(28)
  • 【社招】【中國電信-天翼云】誠聘高級FPGA研發(fā)工程師

    【社招】【中國電信-天翼云】誠聘高級FPGA研發(fā)工程師

    基礎(chǔ)架構(gòu)部門介紹: 天翼云是中國電信旗下云計算品牌,致力于成為領(lǐng)先的云計算服務(wù)提供商。 基礎(chǔ)架構(gòu)部作為天翼云的核心部門,負(fù)責(zé)構(gòu)建天翼云的整個物理基礎(chǔ)設(shè)施。打造了包括紫金DPU、物理服務(wù)器、物理網(wǎng)絡(luò)、RDMA網(wǎng)絡(luò)、操作系統(tǒng)、虛擬化、IDC在內(nèi)的核心底座產(chǎn)品?;?/p>

    2024年02月03日
    瀏覽(27)
  • 博冠光電8K事業(yè)部招聘研發(fā)工程師及產(chǎn)品經(jīng)理

    一、高級結(jié)構(gòu)工程師 工作職責(zé):1、負(fù)責(zé)公司產(chǎn)品的機(jī)械結(jié)構(gòu)設(shè)計、模具開發(fā)和量產(chǎn)導(dǎo)入;2、負(fù)責(zé)機(jī)械結(jié)構(gòu)方向的技術(shù)預(yù)研,包括技術(shù)專題研究,技術(shù)難題攻關(guān);?3、負(fù)責(zé)結(jié)構(gòu)組的技術(shù)管理工作,包括帶新人,材料選型,設(shè)計審核;4、領(lǐng)導(dǎo)安排的其他工作。任職要求:1.、本

    2024年02月12日
    瀏覽(28)
  • 阿里云研發(fā)工程師劉睿:阿里云消息生態(tài)及最佳實(shí)踐

    阿里云研發(fā)工程師劉睿:阿里云消息生態(tài)及最佳實(shí)踐

    2022 年 9 月 24 日,阿里云用戶組(AUG)第 12 期活動在廈門舉辦?;顒蝇F(xiàn)場,阿里云消息中間件研發(fā)工程師劉睿,向參會企業(yè)代表分享了阿里云消息生態(tài)及最佳實(shí)踐。本文根據(jù)演講內(nèi)容整理而成。 眾所周知,消息中間件作為現(xiàn)代軟件體系中的底層基礎(chǔ)軟件,和數(shù)據(jù)庫一樣廣泛

    2023年04月09日
    瀏覽(23)
  • 突破職場競爭,引領(lǐng)未來發(fā)展:考取《研發(fā)效能(DevOps)工程師職業(yè)技術(shù)認(rèn)證》

    突破職場競爭,引領(lǐng)未來發(fā)展:考取《研發(fā)效能(DevOps)工程師職業(yè)技術(shù)認(rèn)證》

    就業(yè)形勢堪憂,什么最有保障?考個“國家級”證書傍身吧! 工信部教考中心作為中國領(lǐng)先的行業(yè)技能認(rèn)證機(jī)構(gòu),其頒發(fā)的認(rèn)證證書不僅代表了個人在信息技術(shù)領(lǐng)域的專業(yè)能力,更可以錄入工業(yè)和信息化技術(shù)技能人才數(shù)據(jù)庫,這是一個重要的信息資源平臺,它可以幫助企業(yè)和

    2024年02月05日
    瀏覽(17)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包