Skip to content

feat: Add --server option to microk8s config for custom hostname (#5270)#5330

Open
Ray0907 wants to merge 1 commit intocanonical:masterfrom
Ray0907:master
Open

feat: Add --server option to microk8s config for custom hostname (#5270)#5330
Ray0907 wants to merge 1 commit intocanonical:masterfrom
Ray0907:master

Conversation

@Ray0907
Copy link

@Ray0907 Ray0907 commented Dec 6, 2025

Allow users to specify a custom hostname/IP for microk8s config output
using --server flag or persistent config file at
$SNAP_DATA/args/config-server.

Supports IPv4, IPv6 (bracketed), and optional custom port.

Summary

Add --server option to microk8s config command, allowing users to
specify
a custom hostname or IP address for the cluster server output instead of
manually replacing IPs after each command.

Closes #5270

Changes

  • Add -s/--server HOST option to specify custom hostname or IP address
  • Support host:port format (e.g., --server k8s.example.com:6443)
  • Support IPv6 addresses with brackets (e.g., --server [::1]:6443)
  • Add persistent configuration via $SNAP_DATA/args/config-server file
  • Add input validation with helpful error messages
  • Add conflict detection when --use-loopback and --server are used
    together
  • Fix edge case when get_default_ip returns "none"

User-facing changes:

  • New --server flag for microk8s config
  • New config file $SNAP_DATA/args/config-server for persistent
    settings

Testing

Manual testing performed:

  • Verified microk8s config --server hostname outputs correct config
  • Verified microk8s config --server hostname:port replaces both host
    and port
  • Verified microk8s config --server [::1]:6443 works correctly for
    IPv6
  • Verified persistent config file is read when present
  • Verified --server flag takes precedence over config file
  • Verified --use-loopback still works as before
  • Verified error handling for invalid inputs

Possible Regressions

None expected. Existing behavior is preserved:

  • Default behavior (using default IP) unchanged
  • --use-loopback flag works as before

Checklist

Notes

Priority order for server address:

  1. --server CLI flag (highest)
  2. $SNAP_DATA/args/config-server file
  3. --use-loopback flag
  4. Default interface IP (lowest)

The cross-node replication mentioned in #5270 is not implemented in this
PR,
as microk8s config is typically only run on the master node (worker
nodes
are blocked by clustered.lock). This could be a future enhancement if
needed.

  Allow users to specify a custom hostname/IP for microk8s config output
  using --server flag or persistent config file at
  /args/config-server.

  Supports IPv4, IPv6 (bracketed), and optional custom port.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

microk8s config to output custom cluster hostname

1 participant