当前位置: 首页 > news >正文

网站开发 价格差异宁德seo推广

网站开发 价格差异,宁德seo推广,网站开发可以多少钱一个月,韶关营销网站开发目录 pod亲和性与反亲和性 pod亲和性 pod反亲和性 pod状态与重启策略 pod状态 pod重启策略 本文主要介绍了pod资源与pod相关的亲和性,以及pod的重启策略 pod亲和性与反亲和性 pod亲和性(podAffinity)有两种 1.podaffinity,…

目录

pod亲和性与反亲和性

pod亲和性

pod反亲和性

 pod状态与重启策略

pod状态

pod重启策略


本文主要介绍了pod资源与pod相关的亲和性,以及pod的重启策略

pod亲和性与反亲和性

pod亲和性(podAffinity)有两种 1.podaffinity,即联系比较紧密的pod更倾向于使用同一个区域 比如tomcat和nginx这样资源的利用效率更高

2.podunaffinity,即两套完全相同,或两套完全不同功能的服务 为了不互相影响容灾效果,或者让服务之间不会互相影响,更倾向于不适用同一个区域

那么如何判断是不是“同一个区域”就非常重要


#查看帮助
kubectl explain pods.spec.affinity.podAffinity
preferredDuringSchedulingIgnoredDuringExecution #软亲和性,尽可能在一起
requiredDuringSchedulingIgnoredDuringExecution  #硬亲和性,一定要在一起

pod亲和性

#硬亲和性
kubectl explain pods.spec.affinity.podAffinity.requiredDuringSchedulingIgnoredDuringExecutionlabelSelector        <Object>     #以标签为筛选条件,选择一组亲和的podnamespaceSelector    <Object>     #以命名空间为筛选条件,选择一组亲和的podnamespaces   <[]string>           #确定命名空间的位置topologyKey  <string> -required-  #拓扑逻辑键,根据xx判断是否是同一位置cat > qinhe-pod1.yaml << EOF
apiVersion: v1 
kind: Pod
metadata:name: qinhe1namespace: defaultlabels:user: ws
spec:containers:- name: qinhe1image: docker.io/library/nginximagePullPolicy: IfNotPresent
EOF
kubectl apply -f qinhe-pod1.yaml    #定义一个初始的pod,后面的pod可以依次为参照echo "
apiVersion: v1
kind: Pod
metadata:name: qinhe2labels:app: app1
spec:containers:- name: qinhe2image: docker.io/library/nginximagePullPolicy: IfNotPresentaffinity:podAffinity:  # 和pod亲和性requiredDuringSchedulingIgnoredDuringExecution:- labelSelector:  # 以标签为筛选条件matchExpressions:  # 以表达式进行匹配- {key: user, operator: In, values: ["ws"]}topologyKey: kubernetes.io/hostname
#带有kubernetes.io/hostname标签相同的被认为是同一个区域,即以主机名区分
#标签的node被认为是统一位置
" > qinhe-pod2.yaml
kubectl apply -f qinhe-pod2.yamlkubectl get pods -owide #因为hostname node1和node2不同,所以只会调度到node1
NAME     READY   STATUS    RESTARTS   AGE   IP             NODE           NOMINATED NODE   READINESS GATES
qinhe1   1/1     Running   0          68s   10.10.179.9    ws-k8s-node1   <none>           <none>
qinhe2   1/1     Running   0          21s   10.10.179.10   ws-k8s-node1   <none>           <none>#修改
...topologyKey: beta.kubernetes.io/arch
... #node1和node2这两个标签都相同
kubectl delete -f qinhe-pod2.yaml
kubectl apply -f qinhe-pod2.yaml
kubectl get pods -owide #再查看时会发现qinhe2分到了node2
NAME     READY   STATUS    RESTARTS   AGE     IP             NODE           NOMINATED NODE   READINESS GATES
qinhe1   1/1     Running   0          4m55s   10.10.179.9    ws-k8s-node1   <none>           <none>
qinhe2   1/1     Running   0          15s     10.10.234.68   ws-k8s-node2   <none>           <none>#清理环境
kubectl delete -f qinhe-pod1.yaml
kubectl delete -f qinhe-pod2.yaml

pod反亲和性

kubectl explain pods.spec.affinity.podAntiAffinity
preferredDuringSchedulingIgnoredDuringExecution      <[]Object>
requiredDuringSchedulingIgnoredDuringExecution       <[]Object>#硬亲和性
#创建qinhe-pod3.yaml
cat > qinhe-pod3.yaml << EOF
apiVersion: v1 
kind: Pod
metadata:name: qinhe3namespace: defaultlabels:user: ws
spec:containers:- name: qinhe3image: docker.io/library/nginximagePullPolicy: IfNotPresent
EOF#创建qinhe-pod4.yaml
echo "
apiVersion: v1
kind: Pod
metadata:name: qinhe4labels:app: app1
spec:containers:- name: qinhe4image: docker.io/library/nginximagePullPolicy: IfNotPresentaffinity:podAntiAffinity:  # 和pod亲和性requiredDuringSchedulingIgnoredDuringExecution:- labelSelector:  # 以标签为筛选条件matchExpressions:  # 以表达式进行匹配- {key: user, operator: In, values: ["ws"]}  #表达式user=wstopologyKey: kubernetes.io/hostname  #以hostname作为区分是否同个区域
" > qinhe-pod4.yaml
kubectl apply -f qinhe-pod3.yaml
kubectl apply -f qinhe-pod4.yaml
#分配到了不同的node
kubectl get pods -owide
NAME     READY   STATUS    RESTARTS   AGE   IP             NODE           NOMINATED NODE   READINESS GATES
qinhe3   1/1     Running   0          9s    10.10.179.11   ws-k8s-node1   <none>           <none>
qinhe4   1/1     Running   0          8s    10.10.234.70   ws-k8s-node2   <none>           <none>#修改topologyKey
pod4修改为topologyKey: user
kubectl label nodes ws-k8s-node1 user=xhy
kubectl label nodes ws-k8s-node2 user=xhy
#现在node1和node2都会被pod4识别为同一位置,因为node的label中user值相同kubectl delete -f qinhe-pod4.yaml
kubectl apply -f qinhe-pod4.yaml
#直接显示离线
kubectl get pods -owide
NAME     READY   STATUS    RESTARTS   AGE     IP             NODE           NOMINATED NODE   READINESS GATES
qinhe3   1/1     Running   0          9m59s   10.10.179.12   ws-k8s-node1   <none>           <none>
qinhe4   0/1     Pending   0          2s      <none>         <none>         <none>           <none>
#查看日志
Warning  FailedScheduling  74s   default-scheduler  0/4 nodes are available: 2 node(s) didn't match pod anti-affinity rules, 2 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }. preemption: 0/4 nodes are available: 2 No preemption victims found for incoming pod, 2 Preemption is not helpful for scheduling..#pod反亲和性的软亲和性与node亲和性的软亲和性同理#清理环境
kubectl label nodes ws-k8s-node1 user-
kubectl label nodes ws-k8s-node2 user-
kubectl delete -f qinhe-pod3.yaml
kubectl delete -f qinhe-pod4.yaml

 pod状态与重启策略

参考文档:Pod 的生命周期 | Kubernetes

pod状态

1.pending——挂起
(1)正在创建pod,检查存储、网络、下载镜像等问题
(2)条件不满足,比如硬亲和性,污点等调度条件不满足

2.failed——失败
至少有一个容器因为失败而停止,即非0状态退出

3.unknown——未知
apiserver连不上node节点的kubelet,通常是网络问题

4.Error——错误

5.succeeded——成功
pod所有容器成功终止

6.Unschedulable
pod不能被调度

7.PodScheduled
正在调度中

8.Initialized
pod初始化完成

9.ImagePullBackOff
容器拉取失败

10.evicted
node节点资源不足

11.CrashLoopBackOff
容器曾经启动,但又异常退出了

pod重启策略

当容器异常时,可以通过设置RestartPolicy字段,设置pod重启策略来对pod进行重启等操作

#查看帮助
kubectl explain pod.spec.restartPolicy
KIND:     Pod
VERSION:  v1
FIELD:    restartPolicy <string>
DESCRIPTION:Restart policy for all containers within the pod. One of Always, OnFailure,Never. Default to Always. More info:<https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy>Possible enum values:- `"Always"`   #只要异常退出,立即自动重启- `"Never"`    #不会重启容器- `"OnFailure"`#容器错误退出,即退出码不为0时,则自动重启#测试Always策略,创建always.yaml
cat > always.yaml << EOF
apiVersion: v1
kind: Pod
metadata:name: always-podnamespace: default
spec:restartPolicy: Alwayscontainers:- name: test-podimage: docker.io/library/tomcatimagePullPolicy: IfNotPresent
EOF
kubectl apply -f always.yaml
kubectl get po #查看状态
NAME         READY   STATUS    RESTARTS   AGE
always-pod   1/1     Running   0          22s
#进入容器去关闭容器
kubectl exec -it always-pod -- /bin/bash
shutdown.sh
#查看当前状态,可以看到always-pod重启计数器为1
kubectl get po
NAME         READY   STATUS    RESTARTS     AGE
always-pod   1/1     Running   1 (5s ago)   70s#测试never策略,创建never.yaml
cat > never.yaml << EOF
apiVersion: v1
kind: Pod
metadata:name: never-podnamespace: default
spec:restartPolicy: Nevercontainers:- name: test-podimage: docker.io/library/tomcatimagePullPolicy: IfNotPresent
EOF
kubectl apply -f never.yaml
kubectl exec -it never-pod -- /bin/bash
shutdown.sh
#不会重启,状态为completed
kubectl get pods | grep never
never-pod    0/1     Completed   0            73s#测试OnFailure策略,创建onfailure.yaml
cat > onfailure.yaml << EOF
apiVersion: v1
kind: Pod
metadata:name: onfailure-podnamespace: default
spec:restartPolicy: OnFailurecontainers:- name: test-podimage: docker.io/library/tomcatimagePullPolicy: IfNotPresent
EOF
kubectl apply -f onfailure.yaml
#进去后进行异常退出
kubectl exec -it onfailure-pod -- /bin/bash
kill 1
#查看pods状态,已经重启
kubectl get po  | grep onfailure
onfailure-pod   1/1     Running     1 (43s ago)   2m11s
#进入后进行正常退出
kubectl exec -it onfailure-pod -- /bin/bash
shutdown.sh
#查看pods状态,没有重启,进入completed状态
kubectl get po  | grep onfailure
onfailure-pod   0/1     Completed   1             3m58s#清理环境
kubectl delete -f always.yaml
kubectl delete -f never.yaml
kubectl delete -f onfailure.yaml

http://www.15wanjia.com/news/12974.html

相关文章:

  • 怎样做公司网站建设培训学校管理制度大全
  • 私人订制旅游网站建设百度地图导航2021最新版
  • 公司网站开发方案20个排版漂亮的网页设计
  • 珠海品牌设计公司seo的实现方式
  • seo网络推广费用合肥网站优化软件
  • 电商培训机构排名前十seo查询外链
  • 做货代还有什么网站可以加人免费创建自己的网站
  • 即墨网站优化百度流量
  • 昆明网站建设询力鼎科技怎样申请网站
  • 备案期间网站关闭谷歌seo服务商
  • 寻找商机seo优化步骤
  • 如皋做网站的公司整站营销系统
  • 做外贸网站需要多少钱买域名要多少钱一个
  • 内江市住房和城乡建设局网站电话号码建站系统哪个比较好
  • 网站模板安装步骤广告sem是什么意思
  • 张家港公司网站建设郑州seo实战培训
  • 建立网站域名的费用买卖友链
  • 相册管理网站模板下载失败西安seo培训学校
  • 回龙观做网站网站建站公司
  • 网站图片倒计时怎么做的企业内训
  • 网站互联今日最新财经新闻
  • 找做钢筋笼的活网站优帮云排名优化
  • 网站的动态新闻数据库怎么做百度指数的各项功能
  • 主题猫wordpress优化服务内容
  • 临海企业网站设计近10天的时政新闻
  • 织梦html5手机网站模板网络项目资源网
  • 宜州网站建设清远今日头条最新消息
  • 网站关键字排名怎么做四平网站seo
  • 英文网站做百度权重有意义吗怎么提升关键词的质量度
  • 常州网站推广公司在线搜索资源