|
#!/usr/bin/bash |
|
|
|
# Purpose: Mastering Kubernetes One Task at a Time - Ephemeral Storage Volumes with 'emptyDir'-Shared emptyDir Volume in a Pod |
|
# Blog Ref: https://medium.com/the-aws-way/mastering-kubernetes-one-task-at-a-time-ephemeral-storage-volumes-with-emptydir-6cb08546b0ff |
|
# GitHub Ref: https://github.com/jdluther2020/jdluther-kubernetes-io-tasks/ |
|
|
|
# Author's NOTE |
|
# 1. # are comment lines |
|
# 2. Command output wherever helpful is shown inside {} |
|
# 3. Everything is executed on a local dev environment (MacOS) |
|
|
|
# |
|
# OBJECTIVE 1 - CREATE AN EMPTYDIR SHARED VOLUME FOR INTER-CONTAINER COMMUNICATION IN A POD |
|
# - Create a pod with three containers, two sharing an emptyDir volumes type to communicate with each other |
|
# - Ref: https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/ |
|
# |
|
|
|
cat <<EOF | tee emptydir-shared-pod.yaml |
|
apiVersion: v1 |
|
kind: Pod |
|
metadata: |
|
name: emptydir-shared-pod |
|
spec: |
|
volumes: |
|
- name: ehpemeral-volume |
|
emptyDir: {} |
|
containers: |
|
- name: nginx-container |
|
image: nginx |
|
volumeMounts: |
|
- name: ehpemeral-volume |
|
mountPath: /usr/share/nginx/html |
|
- name: debian-container |
|
image: debian |
|
volumeMounts: |
|
- name: ehpemeral-volume |
|
mountPath: /debian-data |
|
command: ['sh', '-c', 'echo "$HOSTNAME: Welcome to Nginx! Message written by Debian at `date`!!" > /debian-data/index.html'] |
|
- name: busyboxplus-container |
|
image: radial/busyboxplus |
|
command: ['sh', '-c', 'sleep 3600'] |
|
restartPolicy: Never |
|
EOF |
|
|
|
# Create pod |
|
kubectl apply -f emptydir-shared-pod.yaml |
|
{ |
|
pod/emptydir-shared-pod created |
|
} |
|
|
|
# Get pod status details and obtain POD_IP for next command |
|
kubectl get -f emptydir-shared-pod.yaml -o wide |
|
{ |
|
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES |
|
emptydir-shared-pod 2/3 NotReady 0 20s 10.244.1.2 basic-multi-node-cluster-worker2 <none> <none> |
|
} |
|
|
|
# Access nginx web server via busyboxplus container |
|
# See message from running nginx rcontainer written by terminated debian continaer. |
|
kubectl exec emptydir-shared-pod -c busyboxplus-container -- curl -s 10.244.1.2 |
|
{ |
|
emptydir-shared-pod: Welcome to Nginx! Message written by Debian at Fri Apr 14 01:35:35 UTC 2023!! |
|
} |
|
|
|
# Proceed to OBJECTIVE 2 |