Kubernetes(k8s)Pod的生命周期

Kubernetes pod 初始化

init C :初始换容器

Pod 能够具有多个容器,应用运行在容器里面,但是它也可能有一个或多个先于应用容器启动的  Init容器

Init 容器与普通的容器非常像,除了如下两点:  

  • Ø Init 容器总是运行到成功完成为止  
  • Ø 每个 Init 容器都必须在下一个 Init 容器启动之前成功完成  

如果 Pod Init 容器失败,Kubernetes 会不断地重启该 Pod,直到  Init 容器成功为止。然而

如果 Pod 对应的 restartPolicy Never,它不会重新启动
 

因为 Init 容器具有与应用程序容器分离的单独镜像,所以它们的启动相关代码具有如下优势:

Init 容器  

init 模板 

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: myapp-container
    image: busybox
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox
    command: ['sh', '-c', 'until nslookup myservice; do echo waiting for myservice; sleep 2; 
done;']
  - name: init-mydb
    image: busybox
    command: ['sh', '-c', 'until nslookup mydb; do echo waiting for mydb; sleep 2; done;']

等待init的初始化。

kind: Service
apiVersion: v1
metadata:
  name: myservice
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

kind: Service
apiVersion: v1
metadata:
  name: mydb
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9377

扫描二维码关注公众号,回复: 10400146 查看本文章

两个initC已经初始换完成

发布了203 篇原创文章 · 获赞 54 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/heian_99/article/details/104162175