InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search
  • Home
  • > Kubernetes

Mac kubernetes – create two container pod with shared volume

on Dec 31, 2022

This tutorial will cover steps to create a pod with nginx container and ubuntu containers with shared volume. Both containers will have the same IP and we can get shell on both of these.

  1. Create config file multi-pod.yml
    apiVersion: v1
    kind: Pod
    metadata:
      name: multi-pod
    spec:
    
      restartPolicy: Never
    
      volumes:
      - name: shared-data
        emptyDir: {}
    
      containers:
    
      - name: nginx-container
        image: nginx
        volumeMounts:
        - name: shared-data
          mountPath: /usr/share/nginx/html
    
      - name: ubuntu-container
        image: ubuntu
        volumeMounts:
        - name: shared-data
          mountPath: /pod-data
        command: ["/bin/sh"]
        args: ["-c", "echo Hello, World!!! > /pod-data/index.html && sleep 3600"]

    We need to add the sleep command to ensure container does not finish running.
  2. Create the pod
    kubectl apply -f multi-pod.yml
  3. Get a shell to the nginx container
    kubectl exec -it multi-pod -c nginx-container -- /bin/bash
  4. Install ifconfig and curl
    apt-get update -y
    apt-get install -y net-tools
    apt-get install -y curl
  5. Run ifconfig
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 10.1.0.45  netmask 255.255.0.0  broadcast 10.1.255.255
            ether 4a:16:6c:5f:36:86  txqueuelen 0  (Ethernet)
            RX packets 24703  bytes 36774193 (35.0 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 13083  bytes 717718 (700.8 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 24  bytes 1930 (1.8 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 24  bytes 1930 (1.8 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  6. Run curl
    curl localhost
    or
    curl 10.1.0.45
    You should see:
    Hello, World!!!
  7. Get a shell to the ubuntu container
    kubectl exec -it multi-pod -c ubuntu-container -- /bin/bash
  8. Repeat above steps to install curl and ifconfig. Notice that the IP address is same as above container and curl works on localhost in same way.

Suggested posts:

  1. Mac – enable and use kubernetes in docker
  2. Docker container – handy commands
  3. document querySelector examples
  4. Chrome extension tutorial – access active page dom
  5. Docker how to add a user to group docker on Linux
  6. Mac docker – create getting-started image and run container using it
  7. Mac podman quick start guide
  8. Mac docker minikube kubernetes – how to get shell access to container
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Kubernetes, Mac Docker
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress