pod使用

创建pod
定义pod属性yaml文件

apiVersion: v1
kind: Pod
metadata:
  name: nginx-busybox
spec:
  containers:
  - name: nginx
    image: nginx
    ports:
    - containerPort: 80
  - name: busybox
    image: busybox
    command: ["/bin/sh"]
    args: ["-c", "while true; do echo hello; sleep 10;done"]
root@ubuntu-128:/home/itcast/working/pod# kubectl create -f nginx_busybox.yaml'
root@ubuntu-128:/home/itcast/working/pod# kubectl get pods
NAME            READY   STATUS              RESTARTS   AGE
nginx-busybox   0/2     ContainerCreating   0          16s

查看pod详细信息

root@ubuntu-128:/home/itcast/working/pod# kubectl describe pods nginx-busybox
Name:               nginx-busybox
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               ubuntu-129/192.168.13.129
Start Time:         Mon, 12 Aug 2019 22:50:52 +0800
Labels:             <none>
Annotations:        <none>
Status:             Running
IP:                 10.244.2.3
Containers:
  nginx:
    Container ID:   docker://2938dc5ad522784d7d2d6fedb1639a1b34ba1aff4bec3e410dfc4aeba9ec8244
    Image:          nginx
    Image ID:       docker-pullable://nginx@sha256:eb3320e2f9ca409b7c0aa71aea3cf7ce7d018f03a372564dbdb023646958770b
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Mon, 12 Aug 2019 22:51:02 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-dp86n (ro)
  busybox:
    Container ID:  docker://32e39dbceb4bc802a1d26b994d715fe33cad16d05011094eaf005dd10e4d6d9f
    Image:         busybox
    Image ID:      docker-pullable://busybox@sha256:9f1003c480699be56815db0f8146ad2e22efea85129b5b5983d0e0fb52d9ab70
    Port:          <none>
    Host Port:     <none>
    Command:
      /bin/sh
    Args:
      -c
      while true; do echo hello; sleep 10;done
    State:          Running
      Started:      Mon, 12 Aug 2019 22:51:10 +0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-dp86n (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-dp86n:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-dp86n
    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  20s   default-scheduler    Successfully assigned default/nginx-busybox to ubuntu-129
  Normal  Pulling    18s   kubelet, ubuntu-129  pulling image "nginx"
  Normal  Pulled     9s    kubelet, ubuntu-129  Successfully pulled image "nginx"
  Normal  Created    9s    kubelet, ubuntu-129  Created container
  Normal  Started    9s    kubelet, ubuntu-129  Started container
  Normal  Pulling    9s    kubelet, ubuntu-129  pulling image "busybox"
  Normal  Pulled     1s    kubelet, ubuntu-129  Successfully pulled image "busybox"
  Normal  Created    1s    kubelet, ubuntu-129  Created container
  Normal  Started    1s    kubelet, ubuntu-129  Started container

pod成功运行


root@ubuntu-128:/home/itcast/working/pod# kubectl get pods
NAME            READY   STATUS    RESTARTS   AGE
nginx-busybox   2/2     Running   0          27s

进入pod

root@ubuntu-128:/home/itcast/working/namespace# kubectl exec nginx-busybox -it sh
Defaulting container name to nginx.
Use 'kubectl describe pod/nginx-busybox -n default' to see all of the containers in this pod.
# wget 127.0.0.1
sh: 1: : not foundound
# ^[[A: not found
# : 2:
#
#
# ^[[A^[[A^[[A^[[A^[[A^[[A
# : 6:
#
#
#
#
# curl http://127.0.0.1

删除pod

root@ubuntu-128:/home/itcast/working/pod# kubectl delete -f nginx_busybox.yaml
pod "nginx-busybox" deleted
发布了135 篇原创文章 · 获赞 16 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/nmjhehe/article/details/99350998
pod