编写配置验证initC
编写 init-pod.yaml文件
vim 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 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-pod.yaml文件
kubectl apply -f init-pod.yaml
kubectl get pod
kubectl get pod -o wide
查看Pod创建的具体运行状态
kubectl describe pod
这里可能会有无用pod干扰 建议先删除无用pod
kubectl delete deployment --all
kubectl delete pod --all
kubectl delete svc nginx-deployment
查看Pod初始化日志
kubectl log myapp-pod init-myservice
编写myservice.yaml文件
vim myservice.yaml
kind: Service
apiVersion: v1
metadata:
name: myservice
spec:
ports:
- protocol: TCP
port: 80
targetPort: 9376
执行myservice.yaml文件
kubectl apply -f myservice.yaml
kubectl get pod
kubectl get svc
kubectl get pod -n kube-system
再次查看pod状态
kubectl get pod
编写mydb.yaml文件
vim mydb.yaml
kind: Service
apiVersion: v1
metadata:
name: mydb
spec:
ports:
- protocol: TCP
port: 80
targetPort: 9377
执行mydb.yaml文件
kubectl apply -f mydb.yaml
kubectl get pod
kubectl get pod -o wide
再次查看Pod状态
kubectl get pod
学习笔记来源。1
尚硅谷kubernetes教程 ↩︎