toolbox.yaml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. name: rook-ceph-tools
  5. labels:
  6. app: rook-ceph-tools
  7. spec:
  8. replicas: 1
  9. selector:
  10. matchLabels:
  11. app: rook-ceph-tools
  12. template:
  13. metadata:
  14. labels:
  15. app: rook-ceph-tools
  16. spec:
  17. dnsPolicy: ClusterFirstWithHostNet
  18. containers:
  19. - name: rook-ceph-tools
  20. image: quay.io/ceph/ceph:v17.2.6
  21. command:
  22. - /bin/bash
  23. - -c
  24. - |
  25. # Replicate the script from toolbox.sh inline so the ceph image
  26. # can be run directly, instead of requiring the rook toolbox
  27. CEPH_CONFIG="/etc/ceph/ceph.conf"
  28. MON_CONFIG="/etc/rook/mon-endpoints"
  29. KEYRING_FILE="/etc/ceph/keyring"
  30. # create a ceph config file in its default location so ceph/rados tools can be used
  31. # without specifying any arguments
  32. write_endpoints() {
  33. endpoints=$(cat ${MON_CONFIG})
  34. # filter out the mon names
  35. # external cluster can have numbers or hyphens in mon names, handling them in regex
  36. # shellcheck disable=SC2001
  37. mon_endpoints=$(echo "${endpoints}"| sed 's/[a-z0-9_-]\+=//g')
  38. DATE=$(date)
  39. echo "$DATE writing mon endpoints to ${CEPH_CONFIG}: ${endpoints}"
  40. cat <<EOF > ${CEPH_CONFIG}
  41. [global]
  42. mon_host = ${mon_endpoints}
  43. [client.admin]
  44. keyring = ${KEYRING_FILE}
  45. EOF
  46. }
  47. # watch the endpoints config file and update if the mon endpoints ever change
  48. watch_endpoints() {
  49. # get the timestamp for the target of the soft link
  50. real_path=$(realpath ${MON_CONFIG})
  51. initial_time=$(stat -c %Z "${real_path}")
  52. while true; do
  53. real_path=$(realpath ${MON_CONFIG})
  54. latest_time=$(stat -c %Z "${real_path}")
  55. if [[ "${latest_time}" != "${initial_time}" ]]; then
  56. write_endpoints
  57. initial_time=${latest_time}
  58. fi
  59. sleep 10
  60. done
  61. }
  62. # read the secret from an env var (for backward compatibility), or from the secret file
  63. ceph_secret=${ROOK_CEPH_SECRET}
  64. if [[ "$ceph_secret" == "" ]]; then
  65. ceph_secret=$(cat /var/lib/rook-ceph-mon/secret.keyring)
  66. fi
  67. # create the keyring file
  68. cat <<EOF > ${KEYRING_FILE}
  69. [${ROOK_CEPH_USERNAME}]
  70. key = ${ceph_secret}
  71. EOF
  72. # write the initial config file
  73. write_endpoints
  74. # continuously update the mon endpoints if they fail over
  75. watch_endpoints
  76. imagePullPolicy: IfNotPresent
  77. tty: true
  78. securityContext:
  79. seccompProfile:
  80. type: RuntimeDefault
  81. runAsNonRoot: false
  82. runAsUser: 0
  83. runAsGroup: 0
  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