kubernetes 資源編排幫助

我們在編寫kubernetes資源清單的時(shí)候有很多細(xì)節(jié)不易記住,特別對于還不熟練的同學(xué),尋找參考摸板是一件麻煩的事,下面介紹兩種獲取參考幫助的手段,足夠大家無往不利

  1. kubectl get --export
    kubectl get -o yaml --export
    我們編寫清單可以在集群找一個(gè)現(xiàn)成的資源摸板,然后修改我們想要的信息在以此創(chuàng)建新的資源,這能解決大部分需要了, kubectl get -o yaml --export 命令獲得的資源內(nèi)容就一個(gè)完美的摸板,-o yaml 用的比較多,--export 關(guān)注的可能就比較少,它的作用是把資源在當(dāng)前集群的一些個(gè)性化數(shù)據(jù)過濾掉,給你一個(gè)清爽的摸板,去感受一下吧!
  2. kubectl explain
    有時(shí)我們通過上面的方法能找到的摸板可能沒有我們要的配置,這時(shí)需要去別處尋找參考,或者去查看api文檔,其實(shí)都可以不用,kubectl explain 可以根據(jù)資源路徑給對應(yīng)資源的子對象,就是其可以包含的字段或?qū)ο?,比如看一個(gè)我不知道configMap卷怎么寫的栗子:
[root@Registry ~]# kubectl explain deployments.spec.template.spec.volumes.configMap
RESOURCE: configMap <Object>

DESCRIPTION:
     ConfigMap represents a configMap that should populate this volume
    Adapts a ConfigMap into a volume.

FIELDS:
   defaultMode  <integer>
     Optional: mode bits to use on created files by default. Must be a value
     between 0 and 0777. Defaults to 0644. Directories within the path are not
     affected by this setting. This might be in conflict with other options that
     affect the file mode, like fsGroup, and the result can be other mode bits
     set.

   items    <[]Object>
     If unspecified, each key-value pair in the Data field of the referenced
     ConfigMap will be projected into the volume as a file whose name is the key
     and content is the value. If specified, the listed keys will be projected
     into the specified paths, and unlisted keys will not be present. If a key is
     specified which is not present in the ConfigMap, the volume setup will error
     unless it is marked optional. Paths must be relative and may not contain the
     '..' path or start with '..'.

   name <string>
     Name of the referent. More info:
     https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names

   optional <boolean>
     Specify whether the ConfigMap or it's keys must be defined

這樣我們就可以了解到configMap下有三個(gè)子對象,分別是name, items, defaultMode, 并且items, defaultMode不是必須的。在進(jìn)一步看items這個(gè)對象,我們就可以寫出配置了,類型是Object或Object列表說名還有子對象。

  volumes: 
  -  configMap:
      defaultMode: 420
      name:  NAME
      items:
        key: keyname
        path:  group/my-username

掛載之后是什么形態(tài)可以親自進(jìn)入容器觀摩一下,常用的做法是細(xì)寫items, 默認(rèn)是已key名做為文件名,里面存放值。
還有一點(diǎn)需要補(bǔ)充,學(xué)好英文,推薦一個(gè)學(xué)習(xí)網(wǎng)站:https://www.duolingo.com/

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容