標籤:html ash eal pod 結構 username value base64編碼 com
前言
在是用kubernetes中,我們對資源的建立大部分都是通過
| 1 |
kubelet create -f RESOURCE.yaml |
剛開看的時候不免有一些迷茫,看不懂文法,不知道怎麼寫;今天本文就介紹一下kubernetes construct文法。
Construct文法其實就是由kubelet格式化成API的post data,提交給apiserver,因此這裡支援yaml,json兩種資料結構的檔案。
Pod資源
| 1234567891011121314151617181920212223242526272829 |
apiVersion: v1 指定api版本,此值必須在kubectl apiversion中kind: Pod 指定建立資源的角色/類型metadata: 資源的中繼資料/屬性name: test 資源的名字,在同一個namespace中必須唯一labels: 設定資源的標籤sex: boy 標籤以key/value的結構存在age: 18spec: #specification of the resource content 指定該資源的內容restartPolicy: Never 表明改容器僅僅運行一次,預設k8s的策略,在此容器退出後,會立即建立一個相同的容器volumes: 定義一組掛載裝置- name: volume 定義一個掛載裝置的名字hostPath: /data/www/html 掛載裝置類型為hostPath,路徑為宿主機下的/data/www/html,這裡裝置類型支援很多種containers: 指定資源中的容器- name: container1 容器的名字image: “docker.coocla.org/ubuntu:last” 容器使用的鏡像地址volumeMounts:- mountPath: /mnt 掛載到容器的某個路徑下name: volume 掛載裝置的名字,與volumes[*].name 需要對應livenessProbe: 容器健康監測httpGet: http形式監測,返回200-399之間,則認為容器正常path: /healthport: 8080initialDelaySeconds: 15 表明第一次檢測在容器啟動後多長時間後開始timeoutSeconds: 1 檢測的逾時時間env: 指定容器中的環境變數- name: str 變數的名字value: "hello world” 變數的值command: ["/bin/bash", "-c"] 覆蓋容器中的Entrypoint,對應Dockefile中的ENTRYPOINTargs: ["/bin/echo", "$(str)"] 對應Dockerfile中CMD參數 |
健康監測還支援另外一種方法:
| 123456 |
exec: 執行命令的方法進行監測,如果其退出碼不為0,則認為容器正常command:- cat- /tmp/healthinitialDelaySeconds: 15timeoutSeconds: 1 |
ReplicationController的文法參數
| 1234567891011121314 |
apiVersion: v1kind: ReplicationControllermetadata:name: nginxspec:replicas: 2 指定rc中pod的個數template: 指定rc中pod的模板,rc中的pod都是按照這個模板來建立的metadata: 指定rc中pod的中繼資料,注意這裡不需要在指定pod的名字,它由rc複製產生labels:app: nginxspec:container:- name: nginximage: nginx |
Service
| 123456789101112131415 |
apiVersion: v1kind: Servicemetadata:name: nginxsvclabels:app: nginxspec: 指定Service中的內容ports: 映射列表- port: 80 service的連接埠porotocal: TCP 映射的協議類型,支援TCP/UDPtargetPort: 80 映射到pod的連接埠name: www.baidu.com 該映射的名字selector: 匹配器port: 80app: nginx 匹配label中app為nginx,port為80的pod |
Secret
| 123456789101112131415 |
apiVersion: v1kind: Secretmetadata:name: mysecrettype: 0paque 定義secret的類型,這裡支援三種類型password: xxx|base64 以key/value的形式定義,value需要經過base64編碼才可以,在secret被掛載到container中後,會以key作為檔案名稱,value的值經過base64解碼作為內容,以檔案的形式存在於container中username: xxx|base64 ---type: kubernetes.io/service-account-token 第二種secret類型,用作建立服務帳號的token,用作處理序間通訊的認證 ---type: kubernetes.io/dockercfg 第三種secret類型,用作在建立container,對docker registry的認證data:.dockercfg: `cat ~/.dockercfg | base64` |
以上為部分資源參數,當然還有更多的參數可以指定,及更多的資源可以通過定義construct來建立。
Kubernetes資源建立yml文法