cockroachdb-petset.yaml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. annotations:
  5. service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
  6. name: cockroachdb
  7. labels:
  8. app: cockroachdb
  9. spec:
  10. ports:
  11. # The main port, served by gRPC, serves Postgres-flavor SQL, internode
  12. # traffic and the cli.
  13. - port: 26257
  14. targetPort: 26257
  15. name: grpc
  16. # The secondary port serves the UI as well as health and debug endpoints.
  17. - port: 8080
  18. targetPort: 8080
  19. name: http
  20. clusterIP: None
  21. selector:
  22. app: cockroachdb
  23. ---
  24. apiVersion: apps/v1alpha1
  25. kind: PetSet
  26. metadata:
  27. name: cockroachdb
  28. spec:
  29. serviceName: "cockroachdb"
  30. replicas: 5
  31. template:
  32. metadata:
  33. labels:
  34. app: cockroachdb
  35. annotations:
  36. pod.alpha.kubernetes.io/initialized: "true"
  37. spec:
  38. containers:
  39. - name: cockroachdb
  40. # Runs the master branch. Not recommended for production, but since
  41. # CockroachDB is in Beta, you don't want to run it in production
  42. # anyway. See
  43. # https://hub.docker.com/r/cockroachdb/cockroach/tags/
  44. # if you prefer to run a beta release.
  45. image: cockroachdb/cockroach
  46. imagePullPolicy: IfNotPresent
  47. ports:
  48. - containerPort: 26257
  49. name: grpc
  50. - containerPort: 8080
  51. name: http
  52. volumeMounts:
  53. - name: datadir
  54. mountPath: /cockroach/cockroach-data
  55. command:
  56. - "/bin/bash"
  57. - "-ecx"
  58. - |
  59. # The use of qualified `hostname -f` is crucial:
  60. # Other nodes aren't able to look up the unqualified hostname.
  61. CRARGS=("start" "--logtostderr" "--insecure" "--host" "$(hostname -f)")
  62. # TODO(tschottdorf): really want to use an init container to do
  63. # the bootstrapping. The idea is that the container would know
  64. # whether it's on the first node and could check whether there's
  65. # already a data directory. If not, it would bootstrap the cluster.
  66. # We will need some version of `cockroach init` back for this to
  67. # work. For now, just do the same in a shell snippet.
  68. # Of course this isn't without danger - if node0 loses its data,
  69. # upon restarting it will simply bootstrap a new cluster and smack
  70. # it into our existing cluster.
  71. # There are likely ways out. For example, the init container could
  72. # query the kubernetes API and see whether any other nodes are
  73. # around, etc. Or, of course, the admin can pre-seed the lost
  74. # volume somehow (and in that case we should provide a better way,
  75. # for example a marker file).
  76. if [ ! "$(hostname)" == "cockroachdb-0" ] || \
  77. [ -e "/cockroach/cockroach-data/COCKROACHDB_VERSION" ]
  78. then
  79. CRARGS+=("--join" "cockroachdb")
  80. fi
  81. /cockroach/cockroach ${CRARGS[*]}
  82. volumes:
  83. - name: datadir
  84. persistentVolumeClaim:
  85. claimName: datadir
  86. volumeClaimTemplates:
  87. - metadata:
  88. name: datadir
  89. annotations:
  90. volume.alpha.kubernetes.io/storage-class: anything
  91. spec:
  92. accessModes:
  93. - "ReadWriteOnce"
  94. resources:
  95. requests:
  96. storage: 1Gi