英文:
Not able to make a folder in elasticsearch pod using yaml file
问题
我想在 Elasticsearch pod 内部创建一个名为 synonyms 的文件夹,位置在 /usr/share/elasticsearch/ 下,我应该如何修改我的部署 YAML 文件以实现这一目标。
这是我的部署清单文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: elasticsearch
namespace: elk
spec:
replicas: 1
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: app-elk
operator: In
values:
- "elastic-tomcat"
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
imagePullPolicy: Always
resources:
requests:
memory: 1Gi
ports:
- containerPort: 9200
protocol: TCP
name: rest
- containerPort: 9300
protocol: TCP
name: inter-node
volumeMounts:
- name: data-volume
mountPath: /usr/share/elasticsearch/data
- name: synonyms-volume # 添加这一行用于 synonyms 文件夹挂载
mountPath: /usr/share/elasticsearch/synonyms # 挂载到 Elasticsearch pod 的路径
env:
- name: cluster.name
value: elasticsearch-cluster
- name: node.name
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: discovery.seed_hosts
value: "elasticsearch-cluster-0.elasticsearch"
- name: cluster.initial_master_nodes
value: "elasticsearch-cluster-0"
- name: ES_JAVA_OPTS
value: "-Xms512m -Xmx512m"
- name: network.host
value: "0.0.0.0"
initContainers:
- name: fix-permissions
image: busybox
command: ["sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
securityContext:
privileged: true
volumeMounts:
- name: data-volume
mountPath: /usr/share/elasticsearch/data
- name: increase-vm-max-map
image: busybox
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
- name: increase-fd-ulimit
image: busybox
command: ["sh", "-c", "ulimit -n 65536"]
securityContext:
privileged: true
volumes:
- name: data-volume
persistentVolumeClaim:
claimName: elasticsearch-pvc # 为数据存储创建一个 PVC
- name: synonyms-volume # 添加这一行用于 synonyms 文件夹挂载
emptyDir: {} # 创建一个空目录供挂载
请注意,我已经在容器部分添加了一个新的 volumeMount 来挂载 synonyms 文件夹,并在 volumes 部分创建了一个名为 synonyms-volume 的空目录,用于挂载到 Elasticsearch pod 内部的 /usr/share/elasticsearch/synonyms 路径上。这样,你就可以在该位置创建 synonyms 文件夹了。
英文:
I want to make a folder called synonyms inside the Elasticsearch pod under this location
/usr/share/elasticsearch/ using my deployment YAML file , what changes should I do so that I can create one folder.
here is my deployment manifest file
apiVersion: apps/v1
kind: Deployment
metadata:
name: elasticsearch
namespace: elk
spec:
replicas: 1
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: app-elk
operator: In
values:
- "elastic-tomcat"
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
imagePullPolicy: Always
resources:
requests:
memory: 1Gi
ports:
- containerPort: 9200
protocol: TCP
name: rest
- containerPort: 9300
protocol: TCP
name: inter-node
volumeMounts:
- name: data-volume
mountPath: /usr/share/elasticsearch/data
env:
- name: cluster.name
value: elasticsearch-cluster
- name: node.name
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: discovery.seed_hosts
value: "elasticsearch-cluster-0.elasticsearch"
- name: cluster.initial_master_nodes
value: "elasticsearch-cluster-0"
- name: ES_JAVA_OPTS
value: "-Xms512m -Xmx512m"
- name: network.host
value: "0.0.0.0"
initContainers:
- name: fix-permissions
image: busybox
command: ["sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
securityContext:
privileged: true
volumeMounts:
- name: data-volume
mountPath: /usr/share/elasticsearch/data
- name: increase-vm-max-map
image: busybox
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
- name: increase-fd-ulimit
image: busybox
command: ["sh", "-c", "ulimit -n 65536"]
securityContext:
privileged: true
volumes:
- name: data-volume
persistentVolumeClaim:
claimName: elasticsearch-pvc # Create a PVC for data storage
please help , the platform I am using google kubernetes engine.
答案1
得分: 2
您可以使用init容器创建文件夹,并使用您正在运行的命令以后根据需求使用主容器。
此外,如果您正在运行多个不同的init容器,您可以使用一个容器来执行多个命令。
dnsPolicy: ClusterFirst
initContainers:
- command:
- sh
- -c
- chown -R 1000:1000 /usr/share/elasticsearch/data
- mkdir /usr/share/elasticsearch/XYZ
- sysctl -w vm.max_map_count=262144
- chmod 777 /usr/share/elasticsearch/data
- chomod 777 /usr/share/elasticsearch/data/node
- chmod g+rwx /usr/share/elasticsearch/data
- chgrp 1000 /usr/share/elasticsearch/data
image: busybox:1.29.2
imagePullPolicy: IfNotPresent
name: set-dir-owner
resources: {}
securityContext:
privileged: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /usr/share/elasticsearch/data
name: elasticsearch-data
restartPolicy: Always
英文:
You can create the folder using init container with command that you are running and utilize it as per requirement later with Main container.
Also, you are running multiple different Init containers you can keep one container with multiple commands
dnsPolicy: ClusterFirst
initContainers:
- command:
- sh
- -c
- chown -R 1000:1000 /usr/share/elasticsearch/data
- mkdir /usr/share/elasticsearch/XYZ
- sysctl -w vm.max_map_count=262144
- chmod 777 /usr/share/elasticsearch/data
- chomod 777 /usr/share/elasticsearch/data/node
- chmod g+rwx /usr/share/elasticsearch/data
- chgrp 1000 /usr/share/elasticsearch/data
image: busybox:1.29.2
imagePullPolicy: IfNotPresent
name: set-dir-owner
resources: {}
securityContext:
privileged: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /usr/share/elasticsearch/data
name: elasticsearch-data
restartPolicy: Always
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论