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

k8s-pod参数详解

目录

  • 概述
  • 创建Pod
    • 编写一个简单的Pod
    • 添加常用参数
    • 为Pod的容器分配资源
    • 网络相关
    • Pod健康检查
      • 启动探针
      • 存活探针
      • 就绪探针
    • 作用整个Pod参数配置
      • 创建docker-registry
    • 卷挂载
  • 结束

概述

  k8s中的pod参数详解。官方文档
  版本 k8s 1.27.x 、busybox:stable-musl、nginx:stable-alpine3.19-perl

创建Pod

编写一个简单的Pod

apiVersion: v1
kind: Pod
# 元数据
metadata:# pod 名称 唯一name: busybox# 命名空间namespace: test# 标签labels:app: busyboxspec:containers:- name: busyboximage: harbor.easzlab.io.local:8443/library/busybox:stable-muslimagePullPolicy: IfNotPresentcommand:- sleep- "3600"restartPolicy: Always
[root@hadoop01 pod]# kubectl get pod -n test
NAME                           READY   STATUS    RESTARTS   AGE
busybox                        1/1     Running   0          25s
tomcat-demo-7ddd4cf4f5-bpskf   1/1     Running   0          7d20h[root@hadoop01 pod]# kubectl exec -it -n test busybox -- sh
/ # 
/ # ls
bin   dev   etc   home  proc  root  sys   tmp   usr   var
/ # 

添加常用参数

apiVersion: v1
kind: Pod
# 元数据
metadata:# pod 名称 唯一name: busybox# 命名空间namespace: test# 标签labels:app: busyboxspec:containers:- name: busyboximage: harbor.easzlab.io.local:8443/library/busybox:stable-musl# 可选值: Always|IfNotPresent|NeverimagePullPolicy: IfNotPresent# 环境变量env:- name: appvalue: busybox# 运行终端 守护进程,不会运行完就结束tty: true# 特权模式 对宿主机有 root 权限securityContext:privileged: true# 工作目录workingDir: /test# 命令command: ["/bin/sh"]# 参数args: ["-c", "while true; do echo hello;sleep 10;done"]restartPolicy: Always
[root@hadoop01 pod]# kubectl apply -f arg-busbox-pod.yaml
pod/busybox created
[root@hadoop01 pod]# kubectl get pod -n test
NAME                           READY   STATUS    RESTARTS   AGE
busybox                        1/1     Running   0          7s
tomcat-demo-7ddd4cf4f5-bpskf   1/1     Running   0          7d22h
[root@hadoop01 pod]# kubectl logs -f busybox -n test
hello
hello
hello
hello
hello
hello
hello

为Pod的容器分配资源

apiVersion: v1
kind: Pod
# 元数据
metadata:# pod 名称 唯一name: busybox# 命名空间namespace: test# 标签labels:app: busyboxspec:restartPolicy: Alwayscontainers:- name: busyboximage: harbor.easzlab.io.local:8443/library/busybox:stable-muslimagePullPolicy: IfNotPresentcommand:- sleep- "3600"resources:# 注意MiB 和 Mb 有区别,1MiB=1024k,而1Mb=100k k8s 使用 Mi 大的# cpu的单位 ,1c=1000m# 最小需要requests:memory: "100Mi"cpu: "1000m"# 最大限制limits:memory: "200Mi"cpu: "1000m"

在这里插入图片描述
注意:因为安装的不是 docker ,所以 crictl stats 并不详细
在这里插入图片描述
如 docker stats 能看出资源限制后的变化。
在这里插入图片描述

网络相关

网络默认配置使用的是 k8s 集群的配置。

在这里插入图片描述
自定义网络配置如下:

apiVersion: v1
kind: Pod
# 元数据
metadata:# pod 名称 唯一name: nginx# 命名空间namespace: test# 标签labels:app: nginx spec:# 使用宿主机的网络,与宿主机共享局域网hostNetwork: false# 可选值:Default | ClusterFirst | ClusterFirstWithHostNet | NonednsPolicy: "None"dnsConfig:nameservers:- 8.8.8.8# 域名映射hostAliases:- ip: 192.168.1.18hostnames:- "foo.local"- "bar.local"containers:- name: nginximage: harbor.easzlab.io.local:8443/library/nginx:stable-alpine3.19-perlimagePullPolicy: IfNotPresentports:- name: defaultcontainerPort: 80# 如果使用hostnetwork 那这里就不能指定端口,配置了也不会生效hostPort: 8080

在这里插入图片描述

Pod健康检查

  有一种情况,容器还是正常运行的,但是服务无法使用;这种场景,一般称之为容器死锁,为了能够迟早的发现这种问题,可以通过对容器做健康检查来迟早发现问题。

在这里插入图片描述

  • 启动探针:启动成功之后才是就绪与存活探针,启动失败,会根据策略重启

  • 就绪探针:如初始化 mysql 等,不会重启,会让服务不可用

  • 存活探针:通过 http tcp grpc 等方式验证容器是否可用

  • 探针示例,后续补充

启动探针

spec:containers:- name: your-containerstartupProbe:httpGet:path: /healthzport: 8080failureThreshold: 30initialDelaySeconds: 120periodSeconds: 10timeoutSeconds: 1successThreshold: 1

存活探针

apiVersion: v1
kind: Pod
metadata:name: myapp-podlabels:app: myapp
spec:containers:- name: myapp-containerimage: myapp:latestports:- containerPort: 80livenessProbe:httpGet:path: /healthzport: 80initialDelaySeconds: 5periodSeconds: 10

  Liveness探针每10秒检查一次http://myapp-pod:8080/healthz,initialDelaySeconds用于指定探针初次执行前的延迟时间。

就绪探针

apiVersion: v1
kind: Pod
metadata:name: myapp-podlabels:app: myapp
spec:containers:- name: myapp-containerimage: myapp:latestports:- containerPort: 80readinessProbe:httpGet:path: /readyzport: 80initialDelaySeconds: 5periodSeconds: 10

  Readiness探针每5秒检查一次http://myapp-pod:8080/readyz,initialDelaySeconds用于指定探针初次执行前的延迟时间。

作用整个Pod参数配置

创建docker-registry

kubectl create secret docker-registry regcred \
--docker-server=<你的镜像仓库服务器> \
--docker-username=<你的用户名> \
--docker-password=<你的密码> \
--docker-email=<你的邮箱地址> \
-n test

卷挂载

结束

http://www.lryc.cn/news/367806.html

相关文章:

  • 一些计算机网络面试题
  • transformer - 注意力机制
  • 三端植物大战僵尸杂交版来了
  • np.hstack()和np.vstack()函数解释
  • 【Linux】进程5——进程优先级
  • CNN简介与实现
  • 【AI大模型】Transformers大模型库(五):AutoModel、Model Head及查看模型结构
  • Hadoop yixing(移行),新增表字段,删除表字段,修改存储格式
  • 使用汇编和proteus实现仿真数码管显示电路
  • 【Unity】官方文档学习-光照系统
  • 1731. 每位经理的下属员工数量
  • 特征筛选LASSO回归封装好的代码、数据集和结果
  • Autosar 通讯栈配置-手动配置PDU及Signal-基于ETAS软件
  • Web前端工资调整:深入剖析与全面解读
  • cesium已知两个点 写一个简单具有动画尾迹效果的抛物线
  • C#中使用Mysql批量新增数据 MySqlBulkCopy
  • ARM-V9 RME(Realm Management Extension)系统架构之系统安全能力的架构差异
  • Ansible——stat模块
  • 第二十节:带你梳理Vue2:Vue子组件向父组件传参(事件传参)
  • 华为od-C卷100分题目 - 10寻找最富裕的小家庭
  • 本地部署AI大模型 —— Ollama文档中文翻译
  • 【前端技术】 ES6 介绍及常用语法说明
  • 程序员具备的职业素养(个人见解)
  • Springboot 开发-- 集成 Activiti 7 流程引擎
  • 一些常用的frida脚本
  • 计算机二级Access操作题总结——简单应用
  • C#操作MySQL从入门到精通(21)——删除数据
  • 【iOS】JSONModel源码阅读笔记
  • 如何离线下载 Microsoft Corporation II Windows Subsystem for Android
  • 使用 flask + qwen 实现 txt2sql 流式输出