[英]Sharing the public directory of an express.js app across all pods in a Kubernetes cluster
我想在Azure AKS上部署的Kubernetes群集中使用卷或永久卷來共享express.js應用程序公共目錄中的文件。 群集具有3個副本。
我嘗試遵循以下步驟: https : //docs.microsoft.com/zh-cn/azure/aks/azure-files-volume 。 我聯系了Kubernetes Slack頻道。 建議我嘗試使用永久卷和永久卷聲明。 我這樣做了,但在任何一個Pod中仍然沒有看到共享目錄。
kind: Deployment
metadata:
name: node-ffmpeg-video-cms-deployment
labels:
app: node-ffmpeg-video-cms
spec:
replicas: 3
template:
metadata:
name: node-ffmpeg-video-cms
labels:
app: node-ffmpeg-video-cms
spec:
containers:
- name: node-ffmpeg-video-cms
image: nodeffmpegvideocmscr.azurecr.io/node-ffmpeg-video-cms:v1
imagePullPolicy: IfNotPresent
volumeMounts:
- name: mystorageaccount17924
mountPath: /www/var/public
restartPolicy: Always
volumes:
- name: mystorageaccount17924
azureFile:
secretName: azure-secret
shareName: node-ffmpeg-video-cms
readOnly: false
selector:
matchLabels:
app: node-ffmpeg-video-cms
---
apiVersion: v1
kind: Service
metadata:
name: node-ffmpeg-video-cms-service
spec:
selector:
app: node-ffmpeg-video-cms
ports:
- port: 3000
type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: sample-storage
# The label is used for matching the exact claim
labels:
usage: sample-storage
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
azureFile:
secretName: azure-secret
shareName: node-ffmpeg-video-cms
readOnly: false
mountOptions:
- dir_mode=0777
- file_mode=0777
- uid=1000
- gid=1000
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: sample-storage-claim
annotations:
volume.beta.kubernetes.io/storage-class: ""
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
selector:
matchLabels:
usage: sample-storage
當我運行kubectl時,請在其中一個pod上描述pod:
Namespace: default
Priority: 0
Node: aks-nodepool1-22998726-0/10.240.0.4
Start Time: Fri, 26 Jul 2019 14:55:29 -0500
Labels: app=node-ffmpeg-video-cms
pod-template-hash=8547d97c69
Annotations: <none>
Status: Running
IP: 10.244.0.24
Controlled By: ReplicaSet/node-ffmpeg-video-cms-deployment-8547d97c69
Containers:
node-ffmpeg-video-cms:
Container ID: docker://4c4f89dfc0058fcaa6fcba0b3dd66e89493715fe4373ffe625eacc0296a45ae1
Image: nodeffmpegvideocmscr.azurecr.io/node-ffmpeg-video-cms:v1
Image ID: docker-pullable://nodeffmpegvideocmscr.azurecr.io/node-ffmpeg-video-cms@sha256:2b949efa8535b59a927efbb4d7c6d24739691fa90fad86c91086dc4cfbadbe23
Port: <none>
Host Port: <none>
State: Running
Started: Fri, 26 Jul 2019 14:55:31 -0500
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-7pb5v (ro)
/www/var/public from mystorageaccount17924 (rw)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
mystorageaccount17924:
Type: AzureFile (an Azure File Service mount on the host and bind mount to the pod)
SecretName: azure-secret
ShareName: node-ffmpeg-video-cms
ReadOnly: false
default-token-7pb5v:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-7pb5v
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events: <none>
若要將公共目錄共享到Azure中的多個部署Pod,可以使用Azure文件共享(如提供的鏈接中所示)。 而你並不需要當您將創建PV / PVC volumes
和volumeMounts
在部署中。
在我的測試中,它工作正常,下面顯示了部署和結果的屏幕截圖:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: nginx
image: nginx:1.15.5
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
volumeMounts:
- name: azure
mountPath: /mnt/azure
volumes:
- name: azure
azureFile:
shareName: aksshare
secretName: azure-secret
readOnly: false
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.