初始化容器
kubernetes 1.3版本引入了init container 初始化容器特性。主要用于在启动应用容器(app container)前来启动一个或多个初始化容器,作为应用容器的一个基础。
# 查看要修改的内核参数
[root@kmaster ~]# sysctl -a|grep vm.overcommit_ratio
vm.overcommit_ratio = 50
# 输出yaml文件
[root@kmaster ~]# kubectl run initpod --image centos --image-pull-policy IfNotPresent --dry-run=client -o yaml -- sleep 3600> /root/pod_yaml/initpod.yaml
[root@kmaster ~]# cd pod_yaml/
[root@kmaster pod_yaml]# ls
initpod.yaml
# 修改yaml文件
[root@kmaster pod_yaml]# vim initpod.yaml
[root@kmaster pod_yaml]# cat initpod.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: initpod
name: initpod
spec:
containers:
- args:
- sleep
- "3600"
image: centos
imagePullPolicy: IfNotPresent
name: initpod
resources: {}
initContainers:
- name: initpod1
image: alpine
imagePullPolicy: IfNotPresent
command: ["/sbin/sysctl","-w","vm.overcommit_ratio=55"]
securityContext:
privileged: true
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
# 编排Pod
[root@kmaster pod_yaml]# kubectl apply -f initpod.yaml
pod/initpod created
[root@kmaster pod_yaml]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
initpod 1/1 Running 0 14s 10.244.69.210 knode2 <none> <none>
# 查看knode2上是否已经修改
[root@knode2 ~]# sysctl -a|grep vm.overcommit_ratio
vm.overcommit_ratio = 55
标签:初始化,Kubernetes,initpod,yaml,kmaster,Pod,root,pod
From: https://www.cnblogs.com/kongshuo/p/17420459.html