Skip to content

Latest commit

 

History

History
143 lines (121 loc) · 3.68 KB

File metadata and controls

143 lines (121 loc) · 3.68 KB

Init Containers

Init Containers
Tips and Tricks

For simulated Practice problems visit KillerCoda.
  1. Create a namespace demeter.

    Solution

    k create ns demeter

  2. In demeter namespace create a pod named stew with an init container named setup with busybox image. Run another container named serve with nginx image.

    Solution

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: stew
      name: stew
      namespace: demeter
    spec:
      initContainers:
        - image: busybox
          name: setup
      containers:
      - image: nginx
        name: serve
      dnsPolicy: ClusterFirst
      restartPolicy: Always
    status: {}

  3. Take stew pod created from demeter namespace, there exist a yaml file pod.yaml for reference & use. create a volume named storage in the stew pod of type emptyDir. Mount storage volume on initContainer at path /set and run a command in init container echo "this is nginx index page" > /set/index.html. Mount same volume in nginx container at path /usr/share/nginx/html. Do these updates in pod.yaml. Delete & create the pod again

    Solution

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: stew
      name: stew
      namespace: demeter
    spec:
      initContainers:
        - image: busybox
          name: setup
          command: ["sh","-c","echo 'this is nginx index page' > /set/index.html"]
          volumeMounts:
            - name: storage
              mountPath: /set
      containers:
      - image: nginx
        name: serve
        volumeMounts:
          - name: storage
            mountPath: /usr/share/nginx/html
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      volumes:
        - name: storage
          emptyDir: {}
    status: {}

  4. Take stew pod created from demeter namespace. Export port 80 of nginx container.

    Solution

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      labels:
        run: stew
      name: stew
      namespace: demeter
    spec:
      initContainers:
        - image: busybox
          name: setup
          command: ["sh","-c","echo 'this is nginx index page' > /set/index.html"]
          volumeMounts:
            - name: storage
              mountPath: /set
      containers:
      - image: nginx
        name: serve
        volumeMounts:
          - name: storage
            mountPath: /usr/share/nginx/html
        ports:
          - containerPort: 80
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      volumes:
        - name: storage
          emptyDir: {}
    status: {}

  5. check IP of stew pod and request it at port 80. Run a temporary busybox pod to perform that.

    Solution

    # check ip of the stew pod
    k get po stew -o wide
    
    # make request on port 80
    wget -qO- <IP>