Doctl / Create Kubernetes Cluster
Create Kubernetes Cluster
Doctl command syntax to create kubernetes cluster. Copyable examples, output expectations, and common mistakes.
$
Terminal doctl k c c --count <3> --region <nyc1> --size <s-1vcpu-2gb> --version <latest> <cluster_name> doctl k c c --count <3> --region <nyc1> --size <s-1vcpu-2gb> --version <latest> <cluster_name> #!/bin/bash
# Create Kubernetes Cluster
doctl {{[k|kubernetes]}} {{[c|cluster]}} {{[c|create]}} --count {{3}} --region {{nyc1}} --size {{s-1vcpu-2gb}} --version {{latest}} {{cluster_name}} import subprocess
# Create Kubernetes Cluster
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"doctl",
"k",
"c",
"c",
"--count",
"<3>",
"--region",
"<nyc1>",
"--size",
"<s-1vcpu-2gb>",
"--version",
"<latest>",
"<cluster_name>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: doctl not found. Please install it first.")
if __name__ == "__main__":
run_command() Terminal Output
Expected runtime feedback
>
Output Creating Kubernetes cluster...
ID Name Region Version Nodes
---------------------------------------------------
abc1234 my-cluster nyc1 latest 3
Cluster created successfully! Command Breakdown
What each part is doing
-
doctl - Base Command
- The executable that performs this operation. Here it runs Doctl before the shell applies any redirect operators.
-
k - k|kubernetes
- The value supplied for k|kubernetes.
-
c - c|cluster
- The value supplied for c|cluster.
-
c - c|create
- The value supplied for c|create.
-
<3> - 3
- The value supplied for 3.
-
<nyc1> - nyc1
- The value supplied for nyc1.
-
<s-1vcpu-2gb> - s 1vcpu 2gb
- The value supplied for s 1vcpu 2gb.
-
<latest> - latest
- The value supplied for latest.
-
<cluster_name> - cluster name
- The value supplied for cluster name.
-
--count - Command Option
- Tool-specific option used by this command invocation.
-
--region - Command Option
- Tool-specific option used by this command invocation.
-
--size - Command Option
- Tool-specific option used by this command invocation.
-
--version - Command Option
- Tool-specific option used by this command invocation.
How To Run
Execution path
- Step 1
Run the command: doctl kubernetes cluster create --count 3 --region nyc1 --size s-1vcpu-2gb --version latest my-cluster
- Step 2
Verify the cluster status with: doctl kubernetes cluster get my-cluster
- Step 3
Access the cluster using kubectl: doctl kubernetes cluster kubeconfig save my-cluster
Alternative Approaches
Comparable commands in other tools
Alternative cloud infrastructure tools for the same job.
Aws / Create Kafka Cluster
aws kafka create-cluster --cluster-name <cluster_name> --broker-node-group-info instanceType=<instance_type>,clientSubnets=<subnet_id1 subnet_id2 ...> --kafka-version <version> --number-of-broker-nodes <number> Devpod / Start Workspace From Github devpod up <github.com/user/repo> -i <vscode>