यह पेज दिखाता है कि एक ही directory में कई मौजूदा volume sources को mount करने के लिएprojected Volume का उपयोग कैसे करें।वर्तमान में secret, configMap, downwardAPI और serviceAccountToken volumes को project किया जा सकता है।
serviceAccountToken कोई volume type नहीं है।आपको कुबरनेट्स क्लस्टर की ज़रूरत पड़ेगी और क्यूब सीटीएल कमांड लाइन साधन को समनुरूप करना होगा ताकि वो आपके क्लस्टर के साथ संवाद कर सकें। हमारी सलाह है की इस टुटोरिअल को क्लस्टर में रन करने के लिए कम से कम दो नोड का इस्तेमाल करे जो कि कंट्रोल प्लेन होस्ट के तरह ना एक्ट करे। अगर आपके पास पहले से क्लस्टर नही है, आप minikube की मदद से वह बना सकते है या आप नीचे दिए हुए इन दो कुबरनेट्स प्लेग्राउंड का इस्तेमाल कर सकते हैं:
संस्करण की जांच करने के लिए, लिखें kubectl version.
इस अभ्यास में आप local files से username और password वाले Secrets बनाते हैं।फिर आप एक ऐसा Pod बनाते हैं जिसमें एक container चलता है, और projected Volume का उपयोग करके
Secrets को उसी shared directory में mount किया जाता है।
यह Pod की configuration file है:
apiVersion: v1
kind: Pod
metadata:
name: test-projected-volume
spec:
containers:
- name: test-projected-volume
image: busybox:1.28
args:
- sleep
- "86400"
volumeMounts:
- name: all-in-one
mountPath: "/projected-volume"
readOnly: true
volumes:
- name: all-in-one
projected:
sources:
- secret:
name: user
- secret:
name: pass
Secrets बनाएं:
# Create files containing the username and password:
echo -n "admin" > ./username.txt
echo -n "1f2d1e2e67df" > ./password.txt
# Package these files into secrets:
kubectl create secret generic user --from-file=./username.txt
kubectl create secret generic pass --from-file=./password.txt
Pod बनाएं:
kubectl apply -f https://k8s.io/examples/pods/storage/projected.yaml
जांचें कि Pod का container चल रहा है, और फिर Pod में होने वाले बदलाव देखें:
kubectl get --watch pod test-projected-volume
आउटपुट इस तरह दिखेगा:
NAME READY STATUS RESTARTS AGE
test-projected-volume 1/1 Running 0 14s
दूसरे terminal में, चल रहे container का shell खोलें:
kubectl exec -it test-projected-volume -- /bin/sh
अपनी shell में, जांचें कि projected-volume directory में आपके projected sources मौजूद हैं:
ls /projected-volume/
Pod और Secrets हटाएँ:
kubectl delete pod test-projected-volume
kubectl delete secret user pass
projected volumes के बारे में और जानें।