ImagePullPolicy

支持3种ImagePullPolicy

  • Always:不管镜像是否存在都会进行一次拉取

  • Never:不管镜像是否存在都不会进行拉取

  • IfNotPresent:只有镜像不存在时,才会进行镜像拉取

默认为IfNotPresent,但是:latest 标签的镜像默认是Always。

拉取镜像时docker会进行检验,如果镜像中的MD5码没有变,则不会拉取镜像数据。

生产环境中应避免使用:latest 标签,开发时可以使用。

访问DNS的策略

通过设置dnsPolicy参数,设置Pod中容器访问DNS的策略

  • ClusterFirst:优先基于cluster domain 后缀,通过kube-dns查询

  • Default:优先从kubelet中配置的DNS查询

默认配置的dnsPolicy是ClusterFirst.

主机名

通过hostname参数设置Pod中的hostname。如果未设置,默认使用PodName作为hostname。

子域名

通过subdomain参数设置Pod的子域名,默认为空。

指定hostname为busybox-2和subdomain伪default-subdomain,完整域名为busybox-2.default-subdomain.default.svc.cluster.local

apiVersion: v1
kind: Pod
metadata:
name: busybox2
labels:
  name: busybox
spec:
  hostname: busybox-2
  subdomain: default-subdomain
  containers:
 - image: busybox
   command:
  - sleep
  - "3600"
  name: busybox

IPC/NET/PID

通过设置hostIPC参数True,使用主机的IPC命名空间,默认为False。

通过设置hostNetwork参数True,使用主机的网络命名空间,默认为False

通过设置hostPID参数True,使用主机的PID命名空间,默认为False

apiVersion: v1
kind: Pod
metadata:
  name: busybox1
  labels:
    name: busybox
spec:
  hostIPC: true
  hostPID: true
  hostNetwork: true
  containers:
  - image: busybox
    command:
   - sleep
   - "3600"
   name: busybox

资源限制

kubernetes通过cgroups限制容器的CPU和内存等计算资源,包括requests和limits等。

  • spec.containers[].resources.limits.cpu CPU上限,可以短暂超过,容器也不会停止

  • spec.containers[].resources.limits.memory 内存上限,不可以超过。如果超过,容器可能被停止或调度到其他资源充足的机器。

results matching ""

    No results matching ""