DEV Community

Cover image for Multi Container Pod
Hamza Shaukat
Hamza Shaukat

Posted on

Multi Container Pod

Sample YAML used in the demo

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app.kubernetes.io/name: MyApp
spec:
  containers:
  - name: myapp-container
    image: busybox:1.28
    env:
    - name: FIRSTNAME
      value: "Piyush"
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']
  initContainers:
  - name: init-myservice
    image: busybox:1.28
    command: ['sh', '-c']
    args: ['until nslookup myservice.default.svc.cluster.local; do echo waiting for myservice; sleep 2; done']
  - name: init-mydb
    image: busybox:1.28
    command: ['sh', '-c']
    args: ['until nslookup mydb.default.svc.cluster.local; do echo waiting for mydb; sleep 2; done']
Enter fullscreen mode Exit fullscreen mode

Commands

k create -f 8.yaml
k get pods
k logs myapp-pod
Enter fullscreen mode Exit fullscreen mode

Specific Logs

k logs myapp-pod  -c  init-myservice
Enter fullscreen mode Exit fullscreen mode

Deploy and Expose Nginx

k create deploy nginx-deploy --image nginx --port 80
k get deploy 
Enter fullscreen mode Exit fullscreen mode
k expose  deploy nginx-deploy --name myservice   --port 80

k logs myapp-pod  -c  init-myservice
k exec -it myapp-pod -- printenv
Enter fullscreen mode Exit fullscreen mode

Top comments (0)