toolbox.yaml 4.2 KB

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