K8S学习之基础十:初始化容器和主容器

init容器和主容器

init容器和主容器的区别

  1. 初始化容器不支持 Readinessprobe,因为他们必须在pod就绪之前运行完成

  2. 每个init容器必须运行成功,下一个才能够运行

    定义两个初始化容器,完成后再运行主容器

    vi pod-init.yaml
    apiVersion: v1
    kind: Pod
    metadata:
    name: myapp-pod
    labels:
    app: myapp
    spec:
    initContainers:

    • name: init-myservice
      image: 172.16.80.140/busybox/busybox:1.28
      imagePullPolicy: IfNotPresent
      command: ['sh', '-c', "sleep 5"]
    • name: init-mydb
      image: 172.16.80.140/busybox/busybox:1.28
      imagePullPolicy: IfNotPresent
      command: ['sh', '-c', "sleep 5"]
      containers:
    • name: myapp-container
      image: 172.16.80.140/busybox/busybox:1.28
      command: ['sh', '-c', 'echo The app is running! && sleep 3600']
复制代码
# 获取百度首页,挂载到init容器中,同时挂载到主容器nginx中
vi pod-init-2.yaml
apiVersion: v1
kind: Pod
metadata:
  name: initnginx
spec:
  initContainers:
  - name: install
    image: 172.16.80.140/busybox/busybox:1.28
    imagePullPolicy: IfNotPresent
    command:
    - wget
    - "-O"
    - "/work-dir/index.html"
    - "https://www.baidu.com"
    volumeMounts:
    - name: workdir
      mountPath: /work-dir
  containers:
  - name: nginx
    image: 172.16.80.140/nginx/nginx:1.26
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 80
    volumeMounts:
    - name: workdir
      mountPath: /usr/share/nginx/html
  dnsPolicy: Default
  volumes:
  - name: workdir
    emptyDir: {}
相关推荐
sthnyph1 小时前
docker compose安装redis
redis·docker·容器
AIMath~1 小时前
雪花算法+ZooKeeper解决方案+RPC是什么
分布式·zookeeper·云原生
W.A委员会1 小时前
Docker基本使用流程
运维·docker·容器
gwjcloud3 小时前
Kubernetes从入门到精通(进阶篇)03
云原生·容器·kubernetes
GuokLiu3 小时前
260502-Clawith-Docker安装过程
运维·docker·容器·claw
日取其半万世不竭3 小时前
PeerTube 部署指南:自建视频托管平台
云原生·eureka·音视频
JesseDev4 小时前
Docker lnmp环境快速搭建开箱即用
运维·docker·容器
小义_5 小时前
【Kubernetes】(十二)配置存储卷
云原生·容器·kubernetes
BduL OWED6 小时前
Docker:基于自制openjdk8镜像 or 官方openjdk8镜像,制作tomcat镜像
docker·容器·tomcat
.柒宇.6 小时前
AI掘金头条项目 Docker Compose 部署完整教程(附踩坑记录)
运维·后端·python·docker·容器·fastapi