Kubernetes学习(二)
二 POD生命周期
initC作用说明
initC举例说明
init-pod.yaml
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 myservicel;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;’]
mydb.yaml
kind: Service
apiVersion: v1
metadata:
name: mydb
spec:
ports:
– protocol: TCP
port: 80
targetPort: 9377
myservice.yaml
kind: Service
apiVersion: v1
metadata:
name: myservicel
spec:
ports:
– protocol: TCP
port: 80
targetPort: 9376
如果initC没有执行成功如下图myapp-pod
创建完成两个svc后,pod的状态如下图