toolbox.yaml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: rook-ceph-tools
  5. namespace: rook-ceph # namespace:cluster
  6. labels:
  7. app: rook-ceph-tools
  8. spec:
  9. replicas: 1
  10. selector:
  11. matchLabels:
  12. app: rook-ceph-tools
  13. template:
  14. metadata:
  15. labels:
  16. app: rook-ceph-tools
  17. spec:
  18. dnsPolicy: ClusterFirstWithHostNet
  19. serviceAccountName: rook-ceph-default
  20. containers:
  21. - name: rook-ceph-tools
  22. image: quay.io/ceph/ceph:v19
  23. command:
  24. - /bin/bash
  25. - -c
  26. - |
  27. # Replicate the script from toolbox.sh inline so the ceph image
  28. # can be run directly, instead of requiring the rook toolbox
  29. CEPH_CONFIG="/etc/ceph/ceph.conf"
  30. MON_CONFIG="/etc/rook/mon-endpoints"
  31. KEYRING_FILE="/etc/ceph/keyring"
  32. # create a ceph config file in its default location so ceph/rados tools can be used
  33. # without specifying any arguments
  34. write_endpoints() {
  35. endpoints=$(cat ${MON_CONFIG})
  36. # filter out the mon names
  37. # external cluster can have numbers or hyphens in mon names, handling them in regex
  38. # shellcheck disable=SC2001
  39. mon_endpoints=$(echo "${endpoints}"| sed 's/[a-z0-9_-]\+=//g')
  40. DATE=$(date)
  41. echo "$DATE writing mon endpoints to ${CEPH_CONFIG}: ${endpoints}"
  42. cat <<EOF > ${CEPH_CONFIG}
  43. [global]
  44. mon_host = ${mon_endpoints}
  45. [client.admin]
  46. keyring = ${KEYRING_FILE}
  47. EOF
  48. }
  49. # watch the endpoints config file and update if the mon endpoints ever change
  50. watch_endpoints() {
  51. # get the timestamp for the target of the soft link
  52. real_path=$(realpath ${MON_CONFIG})
  53. initial_time=$(stat -c %Z "${real_path}")
  54. while true; do
  55. real_path=$(realpath ${MON_CONFIG})
  56. latest_time=$(stat -c %Z "${real_path}")
  57. if [[ "${latest_time}" != "${initial_time}" ]]; then
  58. write_endpoints
  59. initial_time=${latest_time}
  60. fi
  61. sleep 10
  62. done
  63. }
  64. # read the secret from an env var (for backward compatibility), or from the secret file
  65. ceph_secret=${ROOK_CEPH_SECRET}
  66. if [[ "$ceph_secret" == "" ]]; then
  67. ceph_secret=$(cat /var/lib/rook-ceph-mon/secret.keyring)
  68. fi
  69. # create the keyring file
  70. cat <<EOF > ${KEYRING_FILE}
  71. [${ROOK_CEPH_USERNAME}]
  72. key = ${ceph_secret}
  73. EOF
  74. # write the initial config file
  75. write_endpoints
  76. # continuously update the mon endpoints if they fail over
  77. watch_endpoints
  78. imagePullPolicy: IfNotPresent
  79. tty: true
  80. securityContext:
  81. runAsNonRoot: true
  82. runAsUser: 2016
  83. runAsGroup: 2016
  84. capabilities:
  85. drop: ["ALL"]
  86. env:
  87. - name: ROOK_CEPH_USERNAME
  88. valueFrom:
  89. secretKeyRef:
  90. name: rook-ceph-mon
  91. key: ceph-username
  92. volumeMounts:
  93. - mountPath: /etc/ceph
  94. name: ceph-config
  95. - name: mon-endpoint-volume
  96. mountPath: /etc/rook
  97. - name: ceph-admin-secret
  98. mountPath: /var/lib/rook-ceph-mon
  99. readOnly: true
  100. volumes:
  101. - name: ceph-admin-secret
  102. secret:
  103. secretName: rook-ceph-mon
  104. optional: false
  105. items:
  106. - key: ceph-secret
  107. path: secret.keyring
  108. - name: mon-endpoint-volume
  109. configMap:
  110. name: rook-ceph-mon-endpoints
  111. items:
  112. - key: data
  113. path: mon-endpoints
  114. - name: ceph-config
  115. emptyDir: {}
  116. tolerations:
  117. - key: "node.kubernetes.io/unreachable"
  118. operator: "Exists"
  119. effect: "NoExecute"
  120. tolerationSeconds: 5