无法使用yaml文件在elasticsearch pod中创建文件夹。

huangapple go评论131阅读模式
英文:

Not able to make a folder in elasticsearch pod using yaml file

问题

我想在Elasticsearch的pod中创建一个名为synonyms的文件夹,位于/usr/share/elasticsearch/位置下,使用我的部署YAML文件,我需要做哪些更改才能创建这个文件夹。

以下是我的部署清单文件:

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: elasticsearch
  5. namespace: elk
  6. spec:
  7. replicas: 1
  8. selector:
  9. matchLabels:
  10. app: elasticsearch
  11. template:
  12. metadata:
  13. labels:
  14. app: elasticsearch
  15. spec:
  16. affinity:
  17. nodeAffinity:
  18. requiredDuringSchedulingIgnoredDuringExecution:
  19. nodeSelectorTerms:
  20. - matchExpressions:
  21. - key: app-elk
  22. operator: In
  23. values:
  24. - "elastic-tomcat"
  25. containers:
  26. - name: elasticsearch
  27. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
  28. imagePullPolicy: Always
  29. resources:
  30. requests:
  31. memory: 1Gi
  32. ports:
  33. - containerPort: 9200
  34. protocol: TCP
  35. name: rest
  36. - containerPort: 9300
  37. protocol: TCP
  38. name: inter-node
  39. volumeMounts:
  40. - name: data-volume
  41. mountPath: /usr/share/elasticsearch/data
  42. env:
  43. - name: cluster.name
  44. value: elasticsearch-cluster
  45. - name: node.name
  46. valueFrom:
  47. fieldRef:
  48. fieldPath: metadata.name
  49. - name: discovery.seed_hosts
  50. value: "elasticsearch-cluster-0.elasticsearch"
  51. - name: cluster.initial_master_nodes
  52. value: "elasticsearch-cluster-0"
  53. - name: ES_JAVA_OPTS
  54. value: "-Xms512m -Xmx512m"
  55. - name: network.host
  56. value: "0.0.0.0"
  57. initContainers:
  58. - name: fix-permissions
  59. image: busybox
  60. command: ["sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
  61. securityContext:
  62. privileged: true
  63. volumeMounts:
  64. - name: data-volume
  65. mountPath: /usr/share/elasticsearch/data
  66. - name: increase-vm-max-map
  67. image: busybox
  68. command: ["sysctl", "-w", "vm.max_map_count=262144"]
  69. securityContext:
  70. privileged: true
  71. - name: increase-fd-ulimit
  72. image: busybox
  73. command: ["sh", "-c", "ulimit -n 65536"]
  74. securityContext:
  75. privileged: true
  76. volumes:
  77. - name: data-volume
  78. persistentVolumeClaim:
  79. claimName: elasticsearch-pvc # Create a PVC for data storage

请帮忙,我正在使用Google Kubernetes Engine平台。

英文:

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

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: elasticsearch
  5. namespace: elk
  6. spec:
  7. replicas: 1
  8. selector:
  9. matchLabels:
  10. app: elasticsearch
  11. template:
  12. metadata:
  13. labels:
  14. app: elasticsearch
  15. spec:
  16. affinity:
  17. nodeAffinity:
  18. requiredDuringSchedulingIgnoredDuringExecution:
  19. nodeSelectorTerms:
  20. - matchExpressions:
  21. - key: app-elk
  22. operator: In
  23. values:
  24. - "elastic-tomcat"
  25. containers:
  26. - name: elasticsearch
  27. image: docker.elastic.co/elasticsearch/elasticsearch:7.17.5
  28. imagePullPolicy: Always
  29. resources:
  30. requests:
  31. memory: 1Gi
  32. ports:
  33. - containerPort: 9200
  34. protocol: TCP
  35. name: rest
  36. - containerPort: 9300
  37. protocol: TCP
  38. name: inter-node
  39. volumeMounts:
  40. - name: data-volume
  41. mountPath: /usr/share/elasticsearch/data
  42. env:
  43. - name: cluster.name
  44. value: elasticsearch-cluster
  45. - name: node.name
  46. valueFrom:
  47. fieldRef:
  48. fieldPath: metadata.name
  49. - name: discovery.seed_hosts
  50. value: "elasticsearch-cluster-0.elasticsearch"
  51. - name: cluster.initial_master_nodes
  52. value: "elasticsearch-cluster-0"
  53. - name: ES_JAVA_OPTS
  54. value: "-Xms512m -Xmx512m"
  55. - name: network.host
  56. value: "0.0.0.0"
  57. initContainers:
  58. - name: fix-permissions
  59. image: busybox
  60. command: ["sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
  61. securityContext:
  62. privileged: true
  63. volumeMounts:
  64. - name: data-volume
  65. mountPath: /usr/share/elasticsearch/data
  66. - name: increase-vm-max-map
  67. image: busybox
  68. command: ["sysctl", "-w", "vm.max_map_count=262144"]
  69. securityContext:
  70. privileged: true
  71. - name: increase-fd-ulimit
  72. image: busybox
  73. command: ["sh", "-c", "ulimit -n 65536"]
  74. securityContext:
  75. privileged: true
  76. volumes:
  77. - name: data-volume
  78. persistentVolumeClaim:
  79. claimName: elasticsearch-pvc # Create a PVC for data storage

please help , the platform I am using google kubernetes engine.

答案1

得分: 2

您可以使用init container创建文件夹,并使用您正在运行的command根据需要在主容器中使用它。

此外,您可以运行多个不同的Init容器,您可以使用一个容器来运行多个命令。

  1. dnsPolicy: ClusterFirst
  2. initContainers:
  3. - command:
  4. - sh
  5. - -c
  6. - chown -R 1000:1000 /usr/share/elasticsearch/data
  7. - mkdir /usr/share/elasticsearch/XYZ
  8. - sysctl -w vm.max_map_count=262144
  9. - chmod 777 /usr/share/elasticsearch/data
  10. - chomod 777 /usr/share/elasticsearch/data/node
  11. - chmod g+rwx /usr/share/elasticsearch/data
  12. - chgrp 1000 /usr/share/elasticsearch/data
  13. image: busybox:1.29.2
  14. imagePullPolicy: IfNotPresent
  15. name: set-dir-owner
  16. resources: {}
  17. securityContext:
  18. privileged: true
  19. terminationMessagePath: /dev/termination-log
  20. terminationMessagePolicy: File
  21. volumeMounts:
  22. - mountPath: /usr/share/elasticsearch/data
  23. name: elasticsearch-data
  24. restartPolicy: Always

请注意,这是一个YAML配置示例,用于创建具有多个命令的init容器,并设置文件夹的权限和所有权。

英文:

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

  1. dnsPolicy: ClusterFirst
  2. initContainers:
  3. - command:
  4. - sh
  5. - -c
  6. - chown -R 1000:1000 /usr/share/elasticsearch/data
  7. - mkdir /usr/share/elasticsearch/XYZ
  8. - sysctl -w vm.max_map_count=262144
  9. - chmod 777 /usr/share/elasticsearch/data
  10. - chomod 777 /usr/share/elasticsearch/data/node
  11. - chmod g+rwx /usr/share/elasticsearch/data
  12. - chgrp 1000 /usr/share/elasticsearch/data
  13. image: busybox:1.29.2
  14. imagePullPolicy: IfNotPresent
  15. name: set-dir-owner
  16. resources: {}
  17. securityContext:
  18. privileged: true
  19. terminationMessagePath: /dev/termination-log
  20. terminationMessagePolicy: File
  21. volumeMounts:
  22. - mountPath: /usr/share/elasticsearch/data
  23. name: elasticsearch-data
  24. restartPolicy: Always

huangapple
  • 本文由 发表于 2023年8月9日 13:11:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864753.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定