kubernetes in action - Replication Controller
理解这个问题,就是pods在Kubernetes中怎么进行failover
在Kubernetes的work node上有kubelet,会负责监控该work node上的pods,如果有container挂掉了,它会负责重启
但是如果进程没有挂掉,只是hang住,或是死循环,或是死锁了,这个怎么判断
所以还需要引入,liveness probes,用于主动探测Pods是否正常
liveness probe
- An HTTP GET probe performs an HTTP GET request on the container’s IP address, a port and path you specify. If the probe receives a response, and the response code doesn’t represent an error (in other words, if the HTTP response code is 2xx or 3xx), the probe is considered successful. If the server returns an error response code or if it doesn’t respond at all, the probe is considered a failure and the container will be restarted as a result.
- A TCP Socket probe tries to open a TCP connection to the specified port of the container. If the connection is established successfully, the probe is successful. Otherwise, the container is restarted.
- An Exec probe executes an arbitrary command inside the container and checks the command’s exit status code.
If the status code is 0, the probe is successful. All other codes are considered failures.
probe分为三种,Http,Tcp,Exec
创建一个Http Probe,

这样后面,kubelet会定期主动通过定义的probe进行探测,如果probe失败就重启container
通过下面的命令看出当前pod的状态,
$ kubectl get po kubia-liveness
NAME READY STATUS RESTARTS AGE
kubia-liveness 1/1 Running 1 2m
看上一次重启的原因,
When you want to figure out why the previous container terminated, you’ll want to
see those logs instead of the current container’s logs. This can be done by using
the --previous option:
$ kubectl logs mypod --previous
也可以查看pod的详细信息,
$ kubectl describe po kubia-liveness

这里可以看到更详细的restart信息,和具体的liveness probe的命令
Liveness: http-get http://:8080/ delay=0s timeout=1s period=10s #success=1
➥ #failure=3
参数本身也比较好理解,#failure=3,判断failure要重试3次,
其中delay是个比较关键的参数,默认是0,如果你的服务需要初始化时间,很容易造成第一次probe失败,
所以可以设大些,

liveness probe,让我们更有效的探测pod或container的fail,这样kubelet可以更加有效的重启和恢复服务
但是kubelet是在work node上面,如果一个node挂了,怎么办?
这就需要ReplicationController,RC会保障他管理的pod在node间failover
ReplicationController

上面是RC的工作流程图,RC不会去迁移Pod,只是根据数目的对比决定是删除Pod,还是创建新的Pod
从图中,知道有几个要素,

我们如何知道RC管理哪些Pod?通过label selector来筛选(更改RC的label selector或是其中pod的label,都可以改变RC管理的Pod范围)
一般一个RC管理的是同一种的Pod,所以Pod的数目就是副本数,通过replica count来定义 (扩缩容)
最后需要有一个Pod模板,用于创新新的Pod (影响新创建的Pod,不会影响已经在运行的Pod)
Kubernetes是采用declarative approach的方式去管理集群,即你不要下达具体的操作指令,而只需要规定需要达到的状态,比如维护2种RC,每个并发度是10;然后Kubernetes会根据当前的实际状态做具体的操作去满足你所需要的状态
创建RC,


$ kubectl create -f kubia-rc.yaml
replicationcontroller "kubia" created
RC的效果,被删除的Pod,会被重新创建

看RC的状态,
$ kubectl get rc
NAME DESIRED CURRENT READY AGE
kubia 3 3 2 3m
$ kubectl describe rc kubia
看下,实际修改一个RC中的Pod的label,会发生什么?
$ kubectl label pod kubia-dmdck app=foo --overwrite
pod "kubia-dmdck" labeled
该pod会脱离RC的管理,RC会创建一个新的Pod来替代该Pod

可以对RC进行扩缩容,可以通过命令,也可以直接修改rc的配置文件
$ kubectl scale rc kubia --replicas=10
$ kubectl edit rc kubia
删除RC,可以选择保留Pods或不保留
$ kubectl delete rc kubia --cascade=false
replicationcontroller "kubia" deleted
ReplicaSet
新版本的Kubernetes会用replicaSet替换当前的replicationcontroller,

不同在于,首先版本不同,replicaSet属于v1beta2
主要是,selector更为灵活,虽然这里使用matchLabels和原来差不多
但可以使用,matchExpressios

DaemonSet
DaemonSet是种特殊形式,如下图,比如kubelet,就是一种典型的DaemonSet
A DaemonSet makes sure it creates as many pods as there are nodes and deploys each one on its own node

DaemonSet也可以选择部分node,通过nodeSelector

Job
可完成的,就是batch任务

对于Job有两个参数,比较关键
completions,job pod需要被执行几次
parallelism,同时有几个pod被执行

可以通过,activeDeadlineSeconds,来设定最大执行时间,超时会被关闭,算fail
CronJob
定期执行的job

关键是对,schedule的理解,
五项,代表
Minute
Hour
Day of month
Month
Day of week.
"0,15,30,45 * * * *", which means at the 0, 15, 30 and 45 minutes mark of every hour
(first asterisk), of every day of the month (second asterisk), of every month (third
asterisk) and on every day of the week (fourth asterisk)
"0,30 * 1 * *", you wanted it to run every 30 minutes, but only on the first day of the month
"0 3 * * 0",if you want it to run at 3AM every Sunday
对于cronJob,都不可能完全精确时间点执行的,可能因为前面的任务拖延或其他问题导致,我们要设个期限,超出这次cronjob就不执行了,否则会堆积大量的cronjob

kubernetes in action - Replication Controller的更多相关文章
- kubernetes concepts -- Replication Controller
Edit This Page ReplicationController NOTE: A Deployment that configures a ReplicaSet is now the reco ...
- kubernetes进阶之五:Replication Controller&Replica Sets&Deployments
一:Replication Controller RC是kubernetes的核心概念之一.它定义了一个期望的场景即声明某种Pod的副本数量在任意时候都要符合某个预期值. 它由以下几个部分组成: 1. ...
- kubernetes 1.3管中窥豹- RS(Replica Sets):the next-generation Replication Controller
前言 kubernates 1.3出了几个新的概念,其中包括deployments,Replica Sets,并且官网称之为是the next-generation Replication Contr ...
- Replication Controller、Replica Set
假如我们现在有一个Pod正在提供线上的服务,我们来想想一下我们可能会遇到的一些场景: 某次运营活动非常成功,网站访问量突然暴增 运行当前Pod的节点发生故障了,Pod不能正常提供服务了 第一种情况,可 ...
- MVC路由规则以及前后台获取Action、Controller、ID名方法
1.前后台获取Action.Controller.ID名方法 前台页面:ViewContext.RouteData.Values["Action"].ToString(); Vie ...
- MVC前后台获取Action、Controller、ID名方法 以及 路由规则
前后台获取Action.Controller.ID名方法 前台页面:ViewContext.RouteData.Values["Action"].ToString();//获取Ac ...
- C# -- 等待异步操作执行完成的方式 C# -- 使用委托 delegate 执行异步操作 JavaScript -- 原型:prototype的使用 DBHelper类连接数据库 MVC View中获取action、controller、area名称、参数
C# -- 等待异步操作执行完成的方式 C# -- 等待异步操作执行完成的方式 1. 等待异步操作的完成,代码实现: class Program { static void Main(string[] ...
- kubernetes垃圾回收器GarbageCollector Controller源码分析(二)
kubernetes版本:1.13.2 接上一节:kubernetes垃圾回收器GarbageCollector Controller源码分析(一) 主要步骤 GarbageCollector Con ...
- Replication Controller 和 Replica Set
使用Replication Controller . Replica Set管理Pod Replication Controller (RC) 简写为RC,可以使用rc作为kubectl工具的快速管理 ...
随机推荐
- 万维网WWW详解
万维网WWW(World Wide Web)并非某种特殊的计算机网络,万维网是一个个大规模的.联机式的信息储藏所,英文简称Web. 万维网使用链接的方式能非常方便地从英特网上的一个站点访问到一个站点, ...
- .NET垃圾回收机制(一)
垃圾收集器(GarbageCollection)是组成.Net平台一个很重要的部分,.NET垃圾回收机制降低了编程复杂度,使程序员不必分散精力去处理析构.不妨碍设计师进行系统抽象.减少了由于内存运用不 ...
- 洛谷P3348 [ZJOI2016]大森林 [LCT]
传送门 刷了那么久水题之后终于有一题可以来写写博客了. 但是这题太神仙了我还没完全弄懂-- upd:写完博客之后似乎懂了. 思路 首先很容易想到\(O(n^2\log n)\)乘上\(O(\frac{ ...
- Codeforces 1120D Power Tree [最小生成树]
洛谷 Codeforces 这题怎么一个中文题解都没有,是不是你们都认为太水了-- 思路 显然可以用dfs序把每个节点变成给一个区间的叶子节点加上某个数. 显然把叶子序列差分一下变为\(a_1,a_2 ...
- JDBC 返回主键
转载至:https://www.liyongzhen.com/ 上一节课里我们学习通过PreparedStatement对象执行带参数的查询SQL和修改SQL. 这节课我们学习使用 PreparedS ...
- php判断浏览器还是微信打开
本人亲测,但是存在一个小问题,就是用此方法在手机端打开会显示Google Chrome,但是在PC端是没有问题的,现在还在测试,先把第一版代码分享给大家! if(strpos($_SERVER['HT ...
- IDEA手动创建JFinal项目
http://www.jfinal.com/share/674 https://www.oschina.net/question/265150_110300
- SQL允许脏读WITH(NOLOCK)
使用WIHT(NOLOCK)有利也有弊,所以在决定使用之前,你一定需要了解清楚WITH(NOLOCK)的功能和缺陷,看其是否适合你的业务需求,不要觉得它能提升性能,稀里糊涂的就使用它. --事务未提交 ...
- 【工具】idea工具 java代码 gbk转utf8
idea工具 https://github.com/downgoon/gbk2utf8 安装在目录下: /usr/local/gbk2utf8/bin 进入目录后直接执行 gbk2utf8 sourc ...
- Centos6的yum源
更换原因: yum -y install fping 1.阿里云Linux安装软件镜像源 常用的源: 阿里云是最近新出的一个镜像源.得益与阿里云的高速发展,这么大的需求,肯定会推出自己的镜像源.阿里云 ...