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

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐