Skip to main content
tostring(v) converts v to a string. Numbers and booleans are formatted in their natural text representation. Strings pass through unchanged.

Signature

Example

Convert a numeric port variable to a string to use it as a map key or pass it to functions that require strings:
2 becomes "2", which is a valid Kubernetes label value.

Notes

  • tostring is most useful when a typed value (number, bool) needs to be used in a context that requires a string, such as a function argument, label value, or map key.
  • In command strings, string interpolation already converts values automatically. tostring is needed explicitly only in expression contexts.