一、Pod镜像及端口

  • 获取帮助文档
# kubectl explain pod.spec.containers
spec.containers <[]object>
  • pod.spec.containers.imagePullPolicy:镜像的拉取策略
- name <string>
image <string>
imagePullPolicy: <string> #如果标签是latest则默认值是Always,如果是其他标签则默认值是IfNotPresent
Always:总是去仓库下载,latest标签的镜像用
Never:本地有就用,没有就不用
IfNotPresent:本地有用本地的,本地没有去仓库下载
  • pod.spec.containers.ports:端口的暴露
  ports:
- name: http
containerPort: 80
- name: https
containerPort: 443

二、Pod标签及标签选择器和注解

  • pod标签
metadata:
name: pod-demo
namespace: default
labels:
app: myapp
tier: frontend
# kubectl get pods --show-labels  #查看所有pod的标签
# kubectl get pods --show-labels -L app #显示拥有app标签的值
# kubectl get pods --show-labels -L app,run #显示多个标签的标签值
# kubectl get pods --show-labels -l app #过滤拥有app标签的pod
# kubectl get pods --show-labels -l app=myapp #基于等值的标签选择器(=, ==, !=)
# kubectl get pods --show-labels -l "app in (myapp,noapp)" #基于集合关系的标签选择器(in, ontin)
# kubectl label pods pod-demo release=canary  #给pod打标
# kubectl label pods pod-demo release=stable --overwrite #修改标签的值
  • node标签
# kubectl get nodes --show-labels  #基于nodeSelector节点选择器
# kubectl label node node01 disktype=ssd #给node01增加disktype=ssd的标签
  • nodeSelector
spec:
nodeSelector: #使其pod只能运行在拥有disktype=ssd标签的node上
disktype: ssd
  • nodeName
spec:
nodeName: node01 #使其pod只能运行在node01上
  • annotations:与label不同的地方在于它不能用于挑选资源对象,仅用于为对象提供“元数据”
metadata:
annotations:
dongfei.tech/created-by: "cluster admin"
# kubectl describe pods pod-demo |grep Annotations

三、Pod生命周期

1、Pod生命周期中的行为

  1. init container:初始化容器,为主容器准备环境,可以有多个初始化容器(串行执行)
  2. main container:主容器
    1. post start:主容器启动后执行的程序
    2. liveness probe:存活状态监测,监测主进程是否正在运行
    3. readiness probe:就绪状态监测,监测主进程提供的服务是否就绪
    4. pre stop:主容器结束前执行的程序

2、Pod生命周期的状态

  1. Pending:挂起状态
  2. Running:运行状态
  3. Failed:失败状态
  4. Succeeded:成功状态
  5. Unknown:未知状态

3、Pod重启策略

spec:
restartPolicy:
Always:默认,总是重启
OnFailure:Pod失败则会重启
Never:不会重启

四、Pod容器存活性探测和就绪性探测

  • 三种探针类型:ExecAction、TCPSocketAction、HTTPGetAction

1、存活性探测

  • pods.spec.containers.livenessProbe.exec:存活性探测之exec探针
# cat liveness-exec.yaml
apiVersion: v1
kind: Pod
metadata:
name: liveness-exec-pod
namespace: default
spec:
containers:
- name: liveness-exec-container
image: busybox:latest
imagePullPolicy: IfNotPresent
command: ["/bin/sh", "-c","touch /tmp/healthy; sleep 10; rm -rf /tmp/healthy; sleep 3600"]
livenessProbe:
exec:
command: ["test","-e","/tmp/healthy"] #探测命令
initialDelaySeconds: 1 #初始化延迟时间,默认0s
periodSeconds: 3 #隔多长时间探测一次,默认10s
failureThreshold: 3 #探测失败3次为失败,默认3次
successThreshold: 1 #探测成功1次为成功
restartPolicy: Always #探测失败时的重启策略
# kubectl get pods -w #监控POD状态
# kubectl describe pods liveness-exec-pod |grep "Restart Count" #查看Pod重启次数
  • pods.spec.containers.livenessProbe.tcpSocket:存活性探测之tcpSocket探针
  • pods.spec.containers.livenessProbe.httpGet:存活性探测之httpGet探针
# cat liveness-httpget.yaml
apiVersion: v1
kind: Pod
metadata:
name: liveness-httpget-pod
namespace: default
spec:
containers:
- name: liveness-httpget-container
image: dongfeimg/myapp:v1
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
livenessProbe:
httpGet:
port: http
path: /index.html
initialDelaySeconds: 1
periodSeconds: 3
# kubectl exec -it liveness-httpget-pod -- /bin/sh #手动连入pod
/ # rm -f /usr/share/nginx/html/index.html #删除index.html文件,探测失败会重启

2、就绪性探测

  • pods.spec.containers.readinessProbe.httpGet:就绪性探测之httpGet探针
# cat readiness-httpget.yaml
apiVersion: v1
kind: Pod
metadata:
name: readiness-httpget-pod
namespace: default
spec:
containers:
- name: readiness-httpget-container
image: dongfeimg/myapp:v1
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
readinessProbe:
httpGet:
port: http
path: /index.html
initialDelaySeconds: 1
periodSeconds: 3
  • 其他参考存活性探测

五、启动后和终止前钩子

  • pods.spec.containers.lifecycle.postStart:启动后钩子
# cat poststart-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: poststart-pod
namespace: default
spec:
containers:
- name: busybox-httpd
image: busybox:latest
imagePullPolicy: IfNotPresent
lifecycle:
postStart:
exec:
command: ["mkdir","-p","/data/web/html"] #在command命令后执行此命令
command: ["/bin/sh","-c","sleep 3600"]
  • pods.spec.containers.lifecycle.preStop:终止前钩子

5、kubernetes资源清单之Pod应用190709的更多相关文章

  1. kubernetes资源清单之pod

    什么是pod? Pod是一组一个或多个容器(例如Docker容器),具有共享的存储/网络,以及有关如何运行这些容器的规范. Pod的内容始终位于同一地点,并在同一时间安排,并在共享上下文中运行. Po ...

  2. 6、kubernetes资源清单之Pod控制器190714

    一.Pod控制器的类别 ReplicationController:早期唯一的控制器,已废弃 ReplicaSet:控制Pod满足用户期望副本:标签选择器选择由自己管理的Pod副本:Pod资源模板完成 ...

  3. Kubernetes中资源清单与Pod的生命周期(二)

    一.资源清单 1,定义: 在k8s中一般使用yaml格式的文件来创建符合我们预期的资源,这样的yaml被称为资源清单. 使用资源清单创建Pod: kubectl apply -f nginx.yaml ...

  4. kubernetes 资源清单定义入门

    k8s中的资源 什么叫资源? k8s中所有的内容都抽象为资源, 资源实例化之后,叫做对象 在k8s中有哪些资源? 工作负载型资源(workload): Pod ReplicaSet Deploymen ...

  5. kubernetes系列06—kubernetes资源清单定义入门

    本文收录在容器技术学习系列文章总目录 1.认识kubernetes资源 1.1 常用资源/对象 workload工作负载型资源:pod,ReplicaSet,Deployment,StatefulSe ...

  6. 【04】Kubernets:资源清单(pod)

    写在前面的话 前面我们提到过,纯手敲 K8S 名称管理 K8S 服务只是作为我们了解 K8S 的一种方案,而我们最终管理 K8S 的方法还是通过接下来的资源清单的方式进行管理. 所以从本章节开始,将会 ...

  7. (四)Kubernetes 资源清单定义

    Kubernetes常用资源对象 依据资源的主要功能作为分类标准,Kubernetes的API对象大体可分为五个类别,如下: 类型 名称 工作负载(Workload) Pod.ReplicaSet.D ...

  8. Kubernetes 学习5 kubernetes资源清单定义入门

    一.kubernetes是有一个restful风格的 API,把各种操作对象都一律当做资源来管理.并且可通过标准的HTTP请求的方法 GET,PUT,DELETE,POST,等方法来完成操作,不过是通 ...

  9. 4、kubernetes资源清单快速入门190625

    一.资源清单概念 资源/对象的类型 工作负载型资源:Pod, ReplicaSet, Deployment, StatefulSet, DaemonSet, Job, Cronjob, ... 服务发 ...

随机推荐

  1. 织梦DEDECMS 5.7文章列表第一页dedefield.content

    功能介绍:有很多DEDEcms使用者,在二级文章列表中加入了{dede:field.content/},但在二级栏目中的每一页列表中都存在内容:使用该功能可以只在第一页显示. 注意:只针对最新dede ...

  2. JS常用函数原理的实现

    本文针对目前常见的面试题,实现了相应方法的核心原理,部分边界细节未处理.后续也会持续更新,希望对你有所帮助. 1.实现一个call函数 // 思路:将要改变this指向的方法挂到目标this上执行并返 ...

  3. 13、yum

    1.yum yum是管理rpm包的工具 2.yum源(yum仓库) 要使用yum前,需要准备一个yum源(我们也称为yum仓库), 这个可以是一个互联网上的仓库,也可以是本地自己搭建的仓库. 仓库里面 ...

  4. 20199319《Linux内核原理与分析》第十一周作业

    ShellShock攻击实验 什么是ShellShock Shellshock,又称Bashdoor,是在Unix中广泛使用的Bash shell中的一个安全漏洞,首次于2014年9月24日公开.许多 ...

  5. Dubbo 03 Restful风格的API

    目录 Dubbo03 restful风格的API 根路径 协议 版本 用HTTP协议里的动词来实现资源的增删改查 用例 swagger(丝袜哥) OpenAPI 资源 编写API文档 整合Spring ...

  6. Atcoder Regular 099 暴力区间扩张 n/dig(n)极值打表 团分割背包

    C 直接把第一次加在哪里for一遍即可 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) u ...

  7. 使用CreateMetaFile创建WMF文件,并转换为EMF文件

    #include <iostream> #include <stdio.h> #include <WINDOWS.H> #include <shellapi. ...

  8. Gym - 101234J Zero Game (单调队列)

    题意:有一个长度为n的01序列,你可以移动k次,每次将一个数移到任意一个位置,求经过操作后区间连续最大的连续0的个数. “移动”操作看似情况很复杂,不好讨论,但其实无非就两种情况: 一.移动的是1:显 ...

  9. 不知如何摧毁Kendo UI for jQuery小部件?这份指南不得不看

    [Kendo UI for jQuery最新试用版下载] Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support ...

  10. 扩展Puppet – 建立Puppet CA集群

    扩展Puppet – 建立Puppet CA集群  (1 votes, average: 5.00 out of 5) 588 views 2012 年 3 月 4 日Puppet.运维ca.mast ...