kubernetes/kops · error

--name is required

Error message

--name is required

What it means

RunCreateCluster requires an explicit cluster name; if options.ClusterName is empty the command fails with '--name is required'. The name is normally inferred from the positional argument or --name flag, but must be resolvable before checking the state store.

Source

Thrown at cmd/kops/create_cluster.go:561

	}

	// TODO: Reuse rootCommand stateStore logic?

	if c.OutDir == "" {
		if c.Target == cloudup.TargetTerraform {
			c.OutDir = "out/terraform"
		} else {
			c.OutDir = "out"
		}
	}

	clientset, err := f.KopsClient()
	if err != nil {
		return err
	}

	if c.ClusterName == "" {
		return fmt.Errorf("--name is required")
	}

	{
		cluster, err := clientset.GetCluster(ctx, c.ClusterName)
		if err != nil {
			if apierrors.IsNotFound(err) {
				cluster = nil
			} else {
				return err
			}
		}

		if cluster != nil {
			return fmt.Errorf("cluster %q already exists; use 'kops update cluster' to apply changes", c.ClusterName)
		}
	}

	if c.OpenstackNetworkID != "" {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Pass the cluster name as a positional argument: kops create cluster name.example.com
  2. Or set --name name.example.com
  3. Export KOPS_CLUSTER_NAME if relying on the environment
  4. Ensure the wrapper script actually passes the name variable

Example fix

// before
kops create cluster --zones us-east-1a
// after
kops create cluster mycluster.example.com --zones us-east-1a
Defensive patterns

Strategy: validation

Validate before calling

clusterName := argsOrFlag
if clusterName == "" {
	clusterName = os.Getenv("KOPS_CLUSTER_NAME")
}
if clusterName == "" {
	return fmt.Errorf("cluster name required: pass positional arg or --name")
}
if !strings.HasSuffix(clusterName, ".") && !isValidDNSName(clusterName) {
	return fmt.Errorf("cluster name should be a valid DNS name")
}

Prevention

When it happens

Trigger: Calling `kops create cluster` with no cluster-name positional argument and no --name flag, or invoking RunCreateCluster programmatically with an options struct lacking ClusterName.

Common situations: Scripting where the name variable was empty; running the command without arguments expecting an interactive prompt; KOPS_CLUSTER_NAME env var unset.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/5854ec3746210d52. Report an issue: GitHub.