zoukankan      html  css  js  c++  java
  • pod基本操作

    @(kernetes虚拟化学习)[pod基本操作]
    pod基本操作

    创建Pod

    kubectl create -f test_pod.yaml
    

    查询Pod

    kubectl get pod my-pod
    kubectl get pod busybox
    NAME      READY     STATUS              RESTARTS   AGE
    busybox   0/1       ContainerCreating   0          18h
    
    

    查询显示字段含义

    • NAME: Pod的名称
    • READY: Pod的准备状况,右边的数字表示Pod包含的容器总数目,左边的数字表示准备就绪的容器数目。
    • STATUS: Pod的状态。
    • RESTARTS: Pod的重启次数
    • AGE: Pod的运行时间。

     pod的准备状况指的是Pod是否准备就绪以接收请求,Pod的准备状况取决于容器,即所有容器都准备就绪了,Pod才准备就绪。这时候kubernetes的代理服务才会添加Pod作为分发后端,而一旦Pod的准备状况变为false(至少一个容器的准备状况为false),kubernetes会将Pod从代理服务的分发后端移除,即不会分发请求给该Pod。

    kubectl get pod busybox   --output json # 使用JSON格式显示Pod的完整信息
    
    kubectl get pod busybox --output yaml # 使用YAML方式显示Pod的完整信息
    

    kubectl get支持以Go Template方式过滤指定的信息,比如查询Pod的运行状态

    kubectl get pods busybox --output=go-template --template={{.status.phase}}
    Running
    

    查看kubectl describe 支持查询Pod的状态和生命周期事件:

    [root@k8s-master ~]# kubectl describe   pod  busybox
    Name:		busybox
    Namespace:	default
    Node:		k8s-node-1/116.196.105.133
    Start Time:	Thu, 22 Mar 2018 09:51:35 +0800
    Labels:		name=busybox
    		role=master
    Status:		Pending
    IP:		
    Controllers:	<none>
    Containers:
      busybox:
        Container ID:	
        Image:		docker.io/busybox
        Image ID:		
        Port:		
        Command:
          sleep
          360000
        State:			Waiting
          Reason:			ContainerCreating
        Ready:			False
        Restart Count:		0
        Volume Mounts:		<none>
        Environment Variables:	<none>
    Conditions:
      Type		Status
      Initialized 	True 
      Ready 	False 
      PodScheduled 	True 
    No volumes.
    QoS Class:	BestEffort
    Tolerations:	<none>
    Events:
      FirstSeen	LastSeen	Count	From			SubObjectPath	Type		Reason		Message
      ---------	--------	-----	----			-------------	--------	------		-------
      7m		7m		1	{default-scheduler }			Normal		Scheduled	Successfully assigne
    d busybox to k8s-node-1  7m		1m		6	{kubelet k8s-node-1}			Warning		FailedSync	Error syncing pod, s
    kipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request.  details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)"
      6m	13s	27	{kubelet k8s-node-1}		Warning	FailedSync	Error syncing pod, skipping: failed to "StartContain
    er" for "POD" with ImagePullBackOff: "Back-off pulling image "registry.access.redhat.com/rhel7/pod-infrastructure:latest""
    
    • Name: Pod的名称
    • Namespace: Pod的Namespace。
    • Image(s): Pod使用的镜像
    • Node: Pod所在的Node。
    • Start Time: Pod的起始时间
    • Labels: Pod的Label。
    • Status: Pod的状态。
    • Reason: Pod处于当前状态的原因。
    • Message: Pod处于当前状态的信息。
    • IP: Pod的PodIP
    • Replication Controllers: Pod对应的Replication Controller。
    • Containers:Pod中容器的信息
    • Container ID: 容器的ID。
    • Image: 容器的镜像
    • Image ID:镜像的ID。
    • State: 容器的状态。
    • Ready: 容器的准备状况(true表示准备就绪)。
    • Restart Count: 容器的重启次数统计。
    • Environment Variables: 容器的环境变量。
      Conditions: Pod的条件,包含Pod准备状况(true表示准备就绪)
      Volumes: Pod的数据卷。
      Events: 与Pod相关的事件列表。

    删除Pod

    可以通过kubectl delete命令删除Pod:

    kubectl delete pod busybox
    

    批量删除

    kubectl delete pod -all
    

    更新Pod

    Pod在创建以后希望更新Pod,可以在修改Pod的定义文件后执行:

    kubectl replace /path/to/busybox.yaml
    

    因为Pod的很多属性是没办法修改的,比如容器镜像,这时候可以用kubectl replace命令设置--force参数,等效于重新建Pod。

  • 相关阅读:
    Vue 中动态添加class(使用v-bind:class)
    Vue 过滤器的使用
    Huxley 是一个用于Web应用 UI 测试的工具
    showmessage函数里
    [Php] PHPExcel读取Excel文件(或来自客户端上传的)并返回二维数组
    async-validator -- git地址
    Antd Upload组件上传文件至php后端, php拿到对应的文件名(二: vue实现)
    Antd Upload组件上传文件至php后端, php拿到对应的文件名
    对数据库中一个timestamp类型字段时间上作加减
    小学生作文怎么辅导?
  • 原文地址:https://www.cnblogs.com/xiaogongzi/p/8621947.html
Copyright © 2011-2022 走看看