yaml文件語法html
- 大小寫敏感
- 使用縮進表示層級關係
- 縮進時不容許使用Tab鍵,只容許使用空格。
- 縮進的空格數目不重要,只要相同層級的元素左側對齊便可
- # 表示註釋,從這個字符一直到行尾,都會被解析器忽略。
apiVersion: extensions/v1beta1 # 當前配置格式的版本 kind: Deployment # 要建立的資源的類型 metadata: # 資源的元素據 name: nginx1 spec: # 資源的說明書 replicas: 2 # 副本數量 template: # 定義pod模板 metadata: # pod 元數據 labels: # 標籤 name: web spec: # pod 說明 containers: #定義每一個容器的屬性 name和image 是必選項 - name: nginx # " - " 不要忘記由於containers節元素爲列表格式 image: nginx
查找資源時用到的命令node
╭─root@node1 ~ ╰─➤ kubectl explain deploy KIND: Deployment VERSION: extensions/v1beta1 ... # kubectl api-resources # kubectl explain deploy.metadata # kubectl explain deploy.spec # kubectl explain deploy.spec.template # kubectl explain deploy.spec.template.spec # kubectl explain deploy.spec.template.metadata
第一步:編寫yml文件nginx
╭─root@node1 ~ ╰─➤ vim nginx.yml ... apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx1 spec: replicas: 2 template: metadata: labels: name: web spec: containers: - name: nginx image: nginx ...
第二步:依靠yml文件運行/刪除web
╭─root@node1 ~ ╰─➤ kubectl apply -f nginx.yml deployment.extensions/nginx1 created # kubectl delete -f nginx.yml # 刪除
第三步:查看podsvim
╭─root@node1 ~ ╰─➤ kubectl get pod NAME READY STATUS RESTARTS AGE nginx1-99f7df68c-7v5pb 1/1 Running 0 77s nginx1-99f7df68c-lcvrk 1/1 Running 0 77s
command、args兩項實現覆蓋Dockerfile中ENTRYPOINT的功能,具體的command命令代替ENTRYPOINT的命令行,args表明集體的參數。api
- 若是command和args均沒有寫,那麼用Dockerfile的配置。
- 若是command寫了,但args沒有寫,那麼Dockerfile默認的配置會被忽略,執行輸入的command(不帶任何參數,固然command中可自帶參數)。
- 若是command沒寫,但args寫了,那麼Dockerfile中配置的ENTRYPOINT的命令行會被執行,而且將args中填寫的參數追加到ENTRYPOINT中。
- 若是command和args都寫了,那麼Dockerfile的配置被忽略,執行command並追加上args參數。好比:
- 另:多命令執行使用sh,-c,[command;command,...]的形式,單條命令的參數填寫在具體的command裏面
摘自:http://www.javashuo.com/article/p-vharvipn-ks.htmlapp
╭─root@node1 ~ ╰─➤ kubectl get po NAME READY STATUS RESTARTS AGE pod-secret 0/1 ContainerCreating 0 9m35s ╭─root@node1 ~ ╰─➤ kubectl get pod pod-secret -o yaml apiVersion: v1 kind: Pod metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"pod-secret","namespace":"default"},"spec":{"containers":[{"command":["/bin/sh","-c","touch test;sleep 60000"],"image":"busybox","imagePullPolicy":"IfNotPresent","name":"busybox","volumeMounts":[{"mountPath":"/tmp","name":"du"}]}],"volumes":[{"name":"du","secret":{"secretName":"mysecret"}}]}} creationTimestamp: "2019-08-31T01:20:35Z" name: pod-secret namespace: default resourceVersion: "267900" selfLink: /api/v1/namespaces/default/pods/pod-secret uid: a222ab7e-cafc-46b3-8a82-8ab1b4fc0599 spec: containers: - command: - /bin/sh - -c - touch test;sleep 60000 image: busybox imagePullPolicy: IfNotPresent name: busybox resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File volumeMounts: - mountPath: /tmp name: du - mountPath: /var/run/secrets/kubernetes.io/serviceaccount name: default-token-ngn4n readOnly: true dnsPolicy: ClusterFirst enableServiceLinks: true nodeName: node2 priority: 0 restartPolicy: Always schedulerName: default-scheduler securityContext: {} serviceAccount: default serviceAccountName: default terminationGracePeriodSeconds: 30 tolerations: - effect: NoExecute key: node.kubernetes.io/not-ready operator: Exists tolerationSeconds: 300 - effect: NoExecute key: node.kubernetes.io/unreachable operator: Exists tolerationSeconds: 300 volumes: - name: du secret: defaultMode: 420 secretName: mysecret - name: default-token-ngn4n secret: defaultMode: 420 secretName: default-token-ngn4n status: conditions: - lastProbeTime: null lastTransitionTime: "2019-08-31T01:26:25Z" status: "True" type: Initialized - lastProbeTime: null lastTransitionTime: "2019-08-31T01:26:25Z" message: 'containers with unready status: [busybox]' reason: ContainersNotReady status: "False" type: Ready - lastProbeTime: null lastTransitionTime: "2019-08-31T01:26:25Z" message: 'containers with unready status: [busybox]' reason: ContainersNotReady status: "False" type: ContainersReady - lastProbeTime: null lastTransitionTime: "2019-08-31T01:26:24Z" status: "True" type: PodScheduled containerStatuses: - image: busybox imageID: "" lastState: {} name: busybox ready: false restartCount: 0 state: waiting: reason: ContainerCreating hostIP: 192.168.137.4 phase: Pending qosClass: BestEffort startTime: "2019-08-31T01:26:25Z"