KUBERNETES-1-3-资源清单

1.kubectl explain pods可以看到创建pod的五个必要参数,apiVersion,kind ,metadata ,spec  , status  。这里还可以通过增加  .  的方式进一步深度查询。

[root@master ~]# kubectl explain pods
KIND:     Pod
VERSION:  v1

DESCRIPTION:
     Pod is a collection of containers that can run on a host. This resource is
     created by clients and scheduled onto hosts.

FIELDS:
   apiVersion    <string>
     APIVersion defines the versioned schema of this representation of an
     object. Servers should convert recognized schemas to the latest internal
     value, and may reject unrecognized values. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#resources

   kind    <string>
     Kind is a string value representing the REST resource this object
     represents. Servers may infer this from the endpoint the client submits
     requests to. Cannot be updated. In CamelCase. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds

   metadata    <Object>
     Standard object's metadata. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata

   spec    <Object>
     Specification of the desired behavior of the pod. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status

   status    <Object>
     Most recently observed status of the pod. This data may not be up to date.
     Populated by the system. Read-only. More info:
     https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
 

2.这里我们尝试通过yaml文件创建pod。

[root@master ~]# mkdir manifests
[root@master ~]# cd manifests
[root@master manifests]# ls
[root@master manifests]# vim pod-demo.yaml
[root@master manifests]# cat pod-demo.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: pod-demo
  namespace: default
  labels:
    app: myapp
    tier: frontend
spec:
  containers:
  - name: myapp
    image: ikubernetes/myapp:v1
  - name: busybox
    image: busybox:latest
    command: 
    - "/bin/sh"
    - "-c"
    - "echo ${date} >> /usr/share/nginx/html/index.html; sleep 5"
[root@master manifests]# kubectl create -f pod-demo.yaml 
pod/pod-demo created

 

3.创建完成后kubectl get pods查看状态。kubectl describe pods pod-demo查看pod详细信息。Events:中会显示过程。  Warning  BackOff    11s (x6 over 1m)  kubelet, node1.example.com  Back-off restarting failed container显示有容器发生错误。

原因在于"echo ${date} >> /usr/share/nginx/html/index.html; sleep 5"这里pod之间是没有实现存储共享的,myapp上有nginx,而busybox上没有nginx。这里不展开详细说明,在后面再进行介绍。

[root@master manifests]# kubectl get pods
NAME                          READY     STATUS      RESTARTS   AGE
client                        0/1       Completed   0          1d
myapp-848b5b879b-7h254        1/1       Running     1          1d
myapp-848b5b879b-d7rjs        1/1       Running     1          1d
myapp-848b5b879b-wv5cz        1/1       Running     1          1d
nginx-deploy-5b595999-tj8ms   1/1       Running     1          1d
pod-demo                      2/2       Running     3          1m
[root@master manifests]# kubectl describe pods pod-demo
Name:               pod-demo
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               node1.example.com/172.20.0.129
Start Time:         Sat, 08 Dec 2018 09:18:36 -0500
Labels:             app=myapp
                    tier=frontend
Annotations:        <none>
Status:             Running
IP:                 10.244.1.11
Containers:
  myapp:
    Container ID:   docker://36fc40d82049266d0975eecb2859b66e13d314e42f466d4c768fcb9766eabf3a
    Image:          ikubernetes/myapp:v1
    Image ID:       docker-pullable://ikubernetes/myapp@sha256:9c3dc30b5219788b2b8a4b065f548b922a34479577befb54b03330999d30d513
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Sat, 08 Dec 2018 09:18:37 -0500
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-s5rf4 (ro)
  busybox:
    Container ID:  docker://ff229302ee17d15ec991aad0120ead9de4bb51edfb7553091d501aa05d8e510f
    Image:         busybox:latest
    Image ID:      docker-pullable://busybox@sha256:2a03a6059f21e150ae84b0973863609494aad70f0a80eaeb64bddd8d92465812
    Port:          <none>
    Host Port:     <none>
    Command:
      /bin/sh
      -c
      echo ${date} >> /usr/share/nginx/html/index.html; sleep 5
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Sat, 08 Dec 2018 09:20:02 -0500
      Finished:     Sat, 08 Dec 2018 09:20:07 -0500
    Ready:          False
    Restart Count:  3
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-s5rf4 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-s5rf4:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-s5rf4
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age               From                        Message
  ----     ------     ----              ----                        -------
  Normal   Scheduled  2m                default-scheduler           Successfully assigned default/pod-demo to node1.example.com
  Normal   Pulled     2m                kubelet, node1.example.com  Container image "ikubernetes/myapp:v1" already present on machine
  Normal   Created    2m                kubelet, node1.example.com  Created container
  Normal   Started    2m                kubelet, node1.example.com  Started container
  Normal   Pulling    53s (x4 over 2m)  kubelet, node1.example.com  pulling image "busybox:latest"
  Normal   Pulled     47s (x4 over 2m)  kubelet, node1.example.com  Successfully pulled image "busybox:latest"
  Normal   Created    47s (x4 over 2m)  kubelet, node1.example.com  Created container
  Normal   Started    46s (x4 over 2m)  kubelet, node1.example.com  Started container
  Warning  BackOff    11s (x6 over 1m)  kubelet, node1.example.com  Back-off restarting failed container
[root@master manifests]# kubectl get pods
NAME                          READY     STATUS             RESTARTS   AGE
client                        0/1       Completed          0          1d
myapp-848b5b879b-7h254        1/1       Running            1          1d
myapp-848b5b879b-d7rjs        1/1       Running            1          1d
myapp-848b5b879b-wv5cz        1/1       Running            1          1d
nginx-deploy-5b595999-tj8ms   1/1       Running            1          1d
pod-demo                      1/2       CrashLoopBackOff   5          6m

 

3.除了之前删pod的方法,也可以通过kubectl delete -f pod-demo.yaml 指定yaml文件的方式将起所关联的pod全部删除。
[root@master manifests]# kubectl delete -f pod-demo.yaml 
pod "pod-demo" deleted

[root@master manifests]# kubectl get pods
NAME                          READY     STATUS      RESTARTS   AGE
client                        0/1       Completed   0          1d
myapp-848b5b879b-7h254        1/1       Running     1          1d
myapp-848b5b879b-d7rjs        1/1       Running     1          1d
myapp-848b5b879b-wv5cz        1/1       Running     1          1d
nginx-deploy-5b595999-tj8ms   1/1       Running     1          1d
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值