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

做行业导航网站好学校网站建设板块分析

做行业导航网站好,学校网站建设板块分析,深圳哪家公司做网站好,广告公司推广平台目录 //资源限制官网示例#xff1a;重启策略 //健康检查#xff1a;又称为探针#xff08;Probe#xff09; //资源限制 当定义 Pod 时可以选择性地为每个容器设定所需要的资源数量。 最常见的可设定资源是 CPU 和内存大小#xff0c;以及其他类型的资源。 当为 Pod 中… 目录 //资源限制官网示例重启策略 //健康检查又称为探针Probe //资源限制 当定义 Pod 时可以选择性地为每个容器设定所需要的资源数量。 最常见的可设定资源是 CPU 和内存大小以及其他类型的资源。 当为 Pod 中的容器指定了 request 资源时代表容器运行所需的最小资源量调度器就使用该信息来决定将 Pod 调度到哪个节点上。当还为容器指定了 limit 资源时kubelet 就会确保运行的容器不会使用超出所设的 limit 资源量。kubelet 还会为容器预留所设的 request 资源量 供该容器使用。 如果 Pod 运行所在的节点具有足够的可用资源容器可以使用超出所设置的 request 资源量。不过容器不可以使用超出所设置的 limit 资源量。 如果给容器设置了内存的 limit 值但未设置内存的 request 值Kubernetes 会自动为其设置与内存 limit 相匹配的 request 值。 类似的如果给容器设置了 CPU 的 limit 值但未设置 CPU 的 request 值则 Kubernetes 自动为其设置 CPU 的 request 值 并使之与 CPU 的 limit 值匹配。 官网示例 官网示例 https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container///Pod 和 容器 的资源请求和限制 spec.containers[].resources.requests.cpu //定义创建容器时预分配的CPU资源 spec.containers[].resources.requests.memory //定义创建容器时预分配的内存资源 spec.containers[].resources.limits.cpu //定义 cpu 的资源上限 spec.containers[].resources.limits.memory //定义内存的资源上限//CPU 资源单位 CPU 资源的 request 和 limit 以 cpu 为单位。Kubernetes 中的一个 cpu 相当于1个 vCPU1个超线程。 Kubernetes 也支持带小数 CPU 的请求。spec.containers[].resources.requests.cpu 为 0.5 的容器能够获得一个 cpu 的一半 CPU 资源类似于Cgroup对CPU资源的时间分片。表达式 0.1 等价于表达式 100m毫核表示每 1000 毫秒内容器可以使用的 CPU 时间总量为 0.1*1000 毫秒。 Kubernetes 不允许设置精度小于 1m 的 CPU 资源。 //内存 资源单位 内存的 request 和 limit 以字节为单位。可以以整数表示或者以10为底数的指数的单位E、P、T、G、M、K来表示 或者以2为底数的指数的单位Ei、Pi、Ti、Gi、Mi、Ki来表示。 如1KB10^310001MB10^610000001000KB1GB10^910000000001000MB 1KiB2^1010241MiB2^2010485761024KiBPS在买硬盘的时候操作系统报的数量要比产品标出或商家号称的小一些主要原因是标出的是以 MB、GB为单位的1GB 就是1,000,000,000Byte而操作系统是以2进制为处理单位的因此检查硬盘容量时是以MiB、GiB为单位1GiB2^301,073,741,824相比较而言1GiB要比1GB多出1,073,741,824-1,000,000,00073,741,824Byte所以检测实际结果要比标出的少一些。示例1 apiVersion: v1 kind: Pod metadata:name: frontend spec:containers:- name: appimage: images.my-company.example/app:v4env:- name: MYSQL_ROOT_PASSWORDvalue: passwordresources:requests:memory: 64Micpu: 250mlimits:memory: 128Micpu: 500m- name: log-aggregatorimage: images.my-company.example/log-aggregator:v6resources:requests:memory: 64Micpu: 250mlimits:memory: 128Micpu: 500m此例子中的 Pod 有两个容器。每个容器的 request 值为 0.25 cpu 和 64MiB 内存每个容器的 limit 值为 0.5 cpu 和 128MiB 内存。那么可以认为该 Pod 的总的资源 request 为 0.5 cpu 和 128 MiB 内存总的资源 limit 为 1 cpu 和 256MiB 内存。示例2 vim pod2.yaml apiVersion: v1 kind: Pod metadata:name: frontend spec:containers:- name: webimage: nginxenv:- name: WEB_ROOT_PASSWORDvalue: passwordresources:requests:memory: 64Micpu: 250mlimits:memory: 128Micpu: 500m- name: dbimage: mysqlenv:- name: MYSQL_ROOT_PASSWORDvalue: abc123resources:requests:memory: 512Micpu: 0.5limits:memory: 1Gicpu: 1kubectl apply -f pod2.yaml kubectl describe pod frontendkubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES frontend 2/2 Running 5 15m 10.244.2.4 node02 none nonekubectl describe nodes node02 #由于当前虚拟机有2个CPU所以Pod的CPU Limits一共占用了50% Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits AGE--------- ---- ------------ ---------- --------------- ------------- ---default frontend 500m (25%) 1 (50%) 128Mi (3%) 256Mi (6%) 16mkube-system kube-flannel-ds-amd64-f4pbp 100m (5%) 100m (5%) 50Mi (1%) 50Mi (1%) 19hkube-system kube-proxy-pj4wp 0 (0%) 0 (0%) 0 (0%) 0 (0%) 19h Allocated resources:(Total limits may be over 100 percent, i.e., overcommitted.)Resource Requests Limits-------- -------- ------cpu 600m (30%) 1100m (55%)memory 178Mi (4%) 306Mi (7%)ephemeral-storage 0 (0%) 0 (0%)重启策略 //重启策略restartPolicy当 Pod 中的容器退出时通过节点上的 kubelet 重启容器。适用于 Pod 中的所有容器。 1、Always当容器终止退出后总是重启容器默认策略 2、OnFailure当容器异常退出退出状态码非0时重启容器正常退出则不重启容器 3、Never当容器终止退出从不重启容器。 #注意K8S 中不支持重启 Pod 资源只有删除重建。在用 yaml 方式创建 Deployment 和 StatefulSet 类型时restartPolicy 只能是 Alwayskubectl run 创建 Pod 可以选择 Always,OnFailure,Never 三种策略kubectl edit deployment nginx-deployment ......restartPolicy: Always//示例 vim pod3.yaml apiVersion: v1 kind: Pod metadata:name: foo spec:containers:- name: busyboximage: busyboxargs:- /bin/sh- -c- sleep 30; exit 3kubectl apply -f pod3.yaml//查看Pod状态等容器启动后30秒后执行exit退出进程进入error状态就会重启次数加1 kubectl get pods NAME READY STATUS RESTARTS AGE foo 1/1 Running 1 50skubectl delete -f pod3.yamlvim pod3.yaml apiVersion: v1 kind: Pod metadata:name: foo spec:containers:- name: busyboximage: busyboxargs:- /bin/sh- -c- sleep 30; exit 3restartPolicy: Never #注意跟container同一个级别kubectl apply -f pod3.yaml//容器进入error状态不会进行重启 kubectl get pods -w//健康检查又称为探针Probe 探针是由kubelet对容器执行的定期诊断。探针的三种规则 ●livenessProbe 判断容器是否正在运行。如果探测失败则kubelet会杀死容器并且容器将根据 restartPolicy 来设置 Pod 状态。 如果容器不提供存活探针则默认状态为Success。●readinessProbe 判断容器是否准备好接受请求。如果探测失败端点控制器将从与 Pod 匹配的所有 service endpoints 中剔除删除该Pod的IP地址。 初始延迟之前的就绪状态默认为Failure。如果容器不提供就绪探针则默认状态为Success。●startupProbe这个1.17版本增加的判断容器内的应用程序是否已启动主要针对于不能确定具体启动时间的应用。如果配置了 startupProbe 探测则在 startupProbe 状态为 Success 之前其他所有探针都处于无效状态直到它成功后其他探针才起作用。 如果 startupProbe 失败kubelet 将杀死容器容器将根据 restartPolicy 来重启。如果容器没有配置 startupProbe 则默认状态为 Success。 #注以上规则可以同时定义。在readinessProbe检测成功之前Pod的running状态是不会变成ready状态的。Probe支持三种检查方法 ●exec 在容器内执行指定命令。如果命令退出时返回码为0则认为诊断成功。●tcpSocket 对指定端口上的容器的IP地址进行TCP检查三次握手。如果端口打开则诊断被认为是成功的。●httpGet 对指定的端口和uri路径上的容器的IP地址执行HTTPGet请求。如果响应的状态码大于等于200且小于400则诊断被认为是成功的每次探测都将获得以下三种结果之一 ●成功Success表示容器通过了检测。 ●失败Failure表示容器未通过检测。 ●未知Unknown表示检测没有正常进行。官网示例 https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes///示例1exec方式 apiVersion: v1 kind: Pod metadata:labels:test: livenessname: liveness-exec spec:containers:- name: livenessimage: k8s.gcr.io/busyboxargs:- /bin/sh- -c- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 60livenessProbe:exec:command:- cat- /tmp/healthyfailureThreshold: 1initialDelaySeconds: 5periodSeconds: 5#initialDelaySeconds指定 kubelet 在执行第一次探测前应该等待5秒即第一次探测是在容器启动后的第6秒才开始执行。默认是 0 秒最小值是 0。 #periodSeconds指定了 kubelet 应该每 5 秒执行一次存活探测。默认是 10 秒。最小值是 1。 #failureThreshold: 当探测失败时Kubernetes 将在放弃之前重试的次数。 存活探测情况下的放弃就意味着重新启动容器。就绪探测情况下的放弃 Pod 会被打上未就绪的标签。默认值是 3。最小值是 1。 #timeoutSeconds探测的超时后等待多少秒。默认值是 1 秒。最小值是 1。在 Kubernetes 1.20 版本之前exec 探针会忽略 timeoutSeconds 探针会无限期地 持续运行甚至可能超过所配置的限期直到返回结果为止。可以看到 Pod 中只有一个容器。kubelet 在执行第一次探测前需要等待 5 秒kubelet 会每 5 秒执行一次存活探测。kubelet 在容器内执行命令 cat /tmp/healthy 来进行探测。如果命令执行成功并且返回值为 0kubelet 就会认为这个容器是健康存活的。 当到达第 31 秒时这个命令返回非 0 值kubelet 会杀死这个容器并重新启动它。vim exec.yaml apiVersion: v1 kind: Pod metadata:name: liveness-execnamespace: default spec:containers:- name: liveness-exec-containerimage: busyboximagePullPolicy: IfNotPresentcommand: [/bin/sh,-c,touch /tmp/live ; sleep 30; rm -rf /tmp/live; sleep 3600]livenessProbe:exec:command: [test,-e,/tmp/live]initialDelaySeconds: 1periodSeconds: 3kubectl create -f exec.yamlkubectl describe pods liveness-exec Events:Type Reason Age From Message---- ------ ---- ---- -------Normal Scheduled 51s default-scheduler Successfully assigned default/liveness-exec-pod to node02Normal Pulled 46s kubelet, node02 Container image busybox already present on machineNormal Created 46s kubelet, node02 Created container liveness-exec-containerNormal Started 45s kubelet, node02 Started container liveness-exec-containerWarning Unhealthy 8s (x3 over 14s) kubelet, node02 Liveness probe failed:Normal Killing 8s kubelet, node02 Container liveness-exec-container failed liveness probe,will be restartedkubectl get pods -w NAME READY STATUS RESTARTS AGE liveness-exec 1/1 Running 1 85s//示例2httpGet方式 apiVersion: v1 kind: Pod metadata:labels:test: livenessname: liveness-http spec:containers:- name: livenessimage: k8s.gcr.io/livenessargs:- /serverlivenessProbe:httpGet:path: /healthzport: 8080httpHeaders:- name: Custom-Headervalue: AwesomeinitialDelaySeconds: 3periodSeconds: 3在这个配置文件中可以看到 Pod 也只有一个容器。initialDelaySeconds 字段告诉 kubelet 在执行第一次探测前应该等待 3 秒。periodSeconds 字段指定了 kubelet 每隔 3 秒执行一次存活探测。kubelet 会向容器内运行的服务服务会监听 8080 端口发送一个 HTTP GET 请求来执行探测。如果服务器上 /healthz 路径下的处理程序返回成功代码则 kubelet 认为容器是健康存活的。如果处理程序返回失败代码则 kubelet 会杀死这个容器并且重新启动它。任何大于或等于 200 并且小于 400 的返回代码标示成功其它返回代码都标示失败。vim httpget.yaml apiVersion: v1 kind: Pod metadata:name: liveness-httpgetnamespace: default spec:containers:- name: liveness-httpget-containerimage: soscscs/myapp:v1imagePullPolicy: IfNotPresentports:- name: httpcontainerPort: 80livenessProbe:httpGet:port: httppath: /index.htmlinitialDelaySeconds: 1periodSeconds: 3timeoutSeconds: 10kubectl create -f httpget.yamlkubectl exec -it liveness-httpget -- rm -rf /usr/share/nginx/html/index.htmlkubectl get pods NAME READY STATUS RESTARTS AGE liveness-httpget 1/1 Running 1 2m44s//示例3tcpSocket方式 apiVersion: v1 kind: Pod metadata:name: goproxylabels:app: goproxy spec:containers:- name: goproxyimage: k8s.gcr.io/goproxy:0.1ports:- containerPort: 8080readinessProbe:tcpSocket:port: 8080initialDelaySeconds: 5periodSeconds: 10livenessProbe:tcpSocket:port: 8080initialDelaySeconds: 15periodSeconds: 20这个例子同时使用 readinessProbe 和 livenessProbe 探测。kubelet 会在容器启动 5 秒后发送第一个 readinessProbe 探测。这会尝试连接 goproxy 容器的 8080 端口。如果探测成功kubelet 将继续每隔 10 秒运行一次检测。除了 readinessProbe 探测这个配置包括了一个 livenessProbe 探测。kubelet 会在容器启动 15 秒后进行第一次 livenessProbe 探测。就像 readinessProbe 探测一样会尝试连接 goproxy 容器的 8080 端口。如果 livenessProbe 探测失败这个容器会被重新启动。vim tcpsocket.yaml apiVersion: v1 kind: Pod metadata:name: probe-tcp spec:containers:- name: nginximage: soscscs/myapp:v1livenessProbe:initialDelaySeconds: 5timeoutSeconds: 1tcpSocket:port: 8080periodSeconds: 10failureThreshold: 2kubectl create -f tcpsocket.yamlkubectl exec -it probe-tcp -- netstat -natp Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1/nginx: master prokubectl get pods -w NAME READY STATUS RESTARTS AGE probe-tcp 1/1 Running 0 1s probe-tcp 1/1 Running 1 25s #第一次是 init(5秒) period(10秒) * 2 probe-tcp 1/1 Running 2 45s #第二次是 period(10秒) period(10秒) 重试了两次 probe-tcp 1/1 Running 3 65s//示例4就绪检测 vim readiness-httpget.yaml apiVersion: v1 kind: Pod metadata:name: readiness-httpgetnamespace: default spec:containers:- name: readiness-httpget-containerimage: soscscs/myapp:v1imagePullPolicy: IfNotPresentports:- name: httpcontainerPort: 80readinessProbe:httpGet:port: 80path: /index1.htmlinitialDelaySeconds: 1periodSeconds: 3livenessProbe:httpGet:port: httppath: /index.htmlinitialDelaySeconds: 1periodSeconds: 3timeoutSeconds: 10kubectl create -f readiness-httpget.yaml//readiness探测失败无法进入READY状态 kubectl get pods NAME READY STATUS RESTARTS AGE readiness-httpget 0/1 Running 0 18skubectl exec -it readiness-httpget sh# cd /usr/share/nginx/html/# ls 50x.html index.html# echo 123 index1.html # exitkubectl get pods NAME READY STATUS RESTARTS AGE readiness-httpget 1/1 Running 0 2m31skubectl exec -it readiness-httpget -- rm -rf /usr/share/nginx/html/index.htmlkubectl get pods -w NAME READY STATUS RESTARTS AGE readiness-httpget 1/1 Running 0 4m10s readiness-httpget 0/1 Running 1 4m15s//示例5就绪检测2 vim readiness-myapp.yaml apiVersion: v1 kind: Pod metadata:name: myapp1labels:app: myapp spec:containers:- name: myappimage: soscscs/myapp:v1ports:- name: httpcontainerPort: 80readinessProbe:httpGet:port: 80path: /index.htmlinitialDelaySeconds: 5periodSeconds: 5timeoutSeconds: 10 --- apiVersion: v1 kind: Pod metadata:name: myapp2labels:app: myapp spec:containers:- name: myappimage: soscscs/myapp:v1ports:- name: httpcontainerPort: 80readinessProbe:httpGet:port: 80path: /index.htmlinitialDelaySeconds: 5periodSeconds: 5timeoutSeconds: 10 --- apiVersion: v1 kind: Pod metadata:name: myapp3labels:app: myapp spec:containers:- name: myappimage: soscscs/myapp:v1ports:- name: httpcontainerPort: 80readinessProbe:httpGet:port: 80path: /index.htmlinitialDelaySeconds: 5periodSeconds: 5timeoutSeconds: 10 --- apiVersion: v1 kind: Service metadata:name: myapp spec:selector:app: myapptype: ClusterIPports:- name: httpport: 80targetPort: 80kubectl create -f readiness-myapp.yamlkubectl get pods,svc,endpoints -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/myapp1 1/1 Running 0 3m42s 10.244.2.13 node02 none none pod/myapp2 1/1 Running 0 3m42s 10.244.1.15 node01 none none pod/myapp3 1/1 Running 0 3m42s 10.244.2.14 node02 none noneNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR ...... service/myapp ClusterIP 10.96.138.13 none 80/TCP 3m42s appmyappNAME ENDPOINTS AGE ...... endpoints/myapp 10.244.1.15:80,10.244.2.13:80,10.244.2.14:80 3m42skubectl exec -it pod/myapp1 -- rm -rf /usr/share/nginx/html/index.html//readiness探测失败Pod 无法进入READY状态且端点控制器将从 endpoints 中剔除删除该 Pod 的 IP 地址 kubectl get pods,svc,endpoints -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/myapp1 0/1 Running 0 5m17s 10.244.2.13 node02 none none pod/myapp2 1/1 Running 0 5m17s 10.244.1.15 node01 none none pod/myapp3 1/1 Running 0 5m17s 10.244.2.14 node02 none noneNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR ...... service/myapp ClusterIP 10.96.138.13 none 80/TCP 5m17s appmyappNAME ENDPOINTS AGE ...... endpoints/myapp 10.244.1.15:80,10.244.2.14:80 5m17s//启动、退出动作 vim post.yaml apiVersion: v1 kind: Pod metadata:name: lifecycle-demo spec:containers:- name: lifecycle-demo-containerimage: soscscs/myapp:v1lifecycle: #此为关键字段postStart:exec:command: [/bin/sh, -c, echo Hello from the postStart handler /var/log/nginx/message] preStop:exec:command: [/bin/sh, -c, echo Hello from the poststop handler /var/log/nginx/message]volumeMounts:- name: message-logmountPath: /var/log/nginx/readOnly: falseinitContainers:- name: init-myserviceimage: soscscs/myapp:v1command: [/bin/sh, -c, echo Hello initContainers /var/log/nginx/message]volumeMounts:- name: message-logmountPath: /var/log/nginx/readOnly: falsevolumes:- name: message-loghostPath:path: /data/volumes/nginx/log/type: DirectoryOrCreatekubectl create -f post.yamlkubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES lifecycle-demo 1/1 Running 0 2m8s 10.244.2.28 node02 none nonekubectl exec -it lifecycle-demo -- cat /var/log/nginx/message Hello initContainers Hello from the postStart handler//在 node02 节点上查看 [rootnode02 ~]# cd /data/volumes/nginx/log/ [rootnode02 log]# ls access.log error.log message [rootnode02 log]# cat message Hello initContainers Hello from the postStart handler #由上可知init Container先执行然后当一个主容器启动后Kubernetes 将立即发送 postStart 事件。//删除 pod 后再在 node02 节点上查看 kubectl delete pod lifecycle-demo[rootnode02 log]# cat message Hello initContainers Hello from the postStart handler Hello from the poststop handler #由上可知当在容器被终结之前 Kubernetes 将发送一个 preStop 事件。
http://www.w-s-a.com/news/516442/

相关文章:

  • 宁夏网站开发设计说明书wordpress主题背景图片
  • 同一个阿里云可以做两个网站吗织梦 帝国 学校网站
  • 城阳网站建设培训网站后台怎么上传文件
  • 重庆茂尔建设集团有限公司网站网页制作教程软件
  • 金湖建设工程质量监督网站高端网站建设公司哪里济南兴田德润实惠吗
  • 站酷设计网站官网入口文字设计seo网站推广工具
  • 专业移动网站建设网站建设软件dw
  • 摄影网站设计思想视觉传达毕业设计作品网站
  • 需要优化的网站有哪些设计装修app
  • 数据型网站建设东莞好的网站国外站建设价格
  • 网络营销方法有哪些举例seo应用领域有哪些
  • 建设银行官方网站官网做网站的专业叫什么
  • 矿区网站建设濮阳做网站的公司有哪些
  • 有什么网站可以自己做书甘肃建设厅网站首页
  • 门户网站建设哪专业怎么把自己做的网站登录到网上
  • 如何做网站小编餐饮业手机php网站
  • 备案 网站商城网站设计公司排名
  • 汕头做网站优化公司seo软件简单易排名稳定
  • 如何做众筹网站微网站设计平台
  • 富平做网站十堰优化seo
  • 免费网站空间可访问wordpress弹窗注册代码
  • 东莞网站建设教程南京做代账会计在哪个网站上找
  • 网站开发好了 怎么发布wordpress数据库缓存插件
  • 工业电商网站怎么配色社交网站建设平台
  • 使用pycharm网站开发建一个网站需要什么条件
  • 网站建设哪些是需要外援的问题wordpress商品展示主题
  • 定制网站开发的目的是什么wordpress 增加按钮
  • 建设单位网站经费请示wordpress模板添加授权
  • 国外的电商网站有哪些为进一步加强校园网站建设
  • 专业集团门户网站建设企业微信商城和网站建设