k8s的InitContainer相关yaml

k8s中pod的生命周期与initcontainer测试

在这里插入图片描述

Pod的yaml

apiVersion: vi
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']

Svc的yaml

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

猜你喜欢

转载自blog.csdn.net/m0_38015372/article/details/104758172