K8s进阶

K8s进阶

pod分类

自主式pod

自主式pod总是在前台运行,同时接受k8s管理与调度,当集群中的pod因为某种原因停止,k8s会根据其副本的数量,重新的生成对应的pod

查看pod清单中有哪些字段

[root@master ~]# kubectl explain pod
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>		##api版本
     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/sig-architecture/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/sig-architecture/api-conventions.md#types-kinds

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

   spec <Object>			##详细信息-这里是需要重点配置的
     Specification of the desired behavior of the pod. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/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/sig-architecture/api-conventions.md#spec-and-status

想要查看详细信息就使用kubectl explain pod 想要查看下面的子字段的话kubectl explain pod.apiVersion 即可~~ apiVersion \ kind \ metadata \ spec 这四个字段是必须有的,下面就看看一份简单的pod清单应该长什么样

apiVersion: v1        ##版本为v1
kind: Pod               ##资源类型为Pod
metadata:              ## 元数据,下面是需要配置的子字段,这里缩进字符要保持一致
  name: pod-nginx      ## pod名
  namespace: default    ##pod所在的名称空间
  labels:                   ##标签-- 下面全用KV格式书写,这里我们给这个pod 打上两个标签  ↓
    app: pod-nginx  
    release: bata
spec:           
  containers:              ##容器
  - name: app-container            ##容器名
    image: docker.io/library/nginx:latest     ##镜像地址

现在我们就试试用这个文件创建第一个自主式pod 创建命令 kubectl create -f pod-demo.yaml 删除命令 kubectl delete -f pod-demo.yaml

[root@master ~]# kubectl create -f pod-nginx.yaml
pod/pod-nginx created
[root@master ~]# kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
nginx-6799fc88d8-mndrf   1/1     Running   2          21h
pod-nginx                1/1     Running   0          35s

这样一个自主式pod就创建好了,下面列举了常用的自主式pod可以定义的字段

spec.nodeSelector <map[string]string>
pod.spec.nodeSelector: #指定对象的调度节点,节点必须存在
pod.spec.restartPolicy <string>
pod.spec.restartPolicy:#容器的重启策略。有三种Always(只有退出就重启),OnFailure(失败退出时不重启),Never(只要退出就不重启),kubelet重新启动的已退出容器将以指数退避延迟(10秒,20秒,40秒......)重新启动,上限为五分钟,并在成功执行十分钟后重置
spec.containers.image.imagePullPolicy  <string>        #镜像的下载策略。有三种:Always(总是去仓库下载) ,Never(从不去仓库下载) , IfNotPresent(如果本地没有就去仓库下载) 
spec.containers.ports:        #容器公开的端口列
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值