Skip to content

Get started with Kubernetes

View as Markdown

Create a Kubernetes cluster, connect kubectl on your computer to it, and run a sample web server that answers on a public IP. You need kubectl installed on your computer; see Install Tools on the Kubernetes site.

Kubernetes is offered in Delhi and Chennai. Before you start, choose one of them as the region in MyAccount. If your account is new and you choose Delhi, see Why can I not create a cluster in Delhi? first.

You also need:

  • A security group in that region with inbound rules for TCP port 6443 and UDP port 8472. See Create a security group and Add or edit rules.
  • On a prepaid account, infra credits for 24 hours of the master node and the pool’s nodes.
  1. In MyAccount, under Compute, click Kubernetes, and click Create New Cluster. Create Kubernetes Cluster opens.
  2. Cluster Name is filled in for you. Keep it, or enter your own name of up to 50 letters, digits, hyphens, and underscores.
  3. Choose a Kubernetes Version that your tools support. The cluster keeps its version and its name for its whole life.
  4. Under Plan, select the On-Demand card, which bills the master node by the minute.
  5. Under Worker Node Pool, click Add Node Pool. In the drawer, keep the Node Pool Name and the Static scaling strategy, which keeps a fixed number of nodes. Set Node Count to 2, the fewest a CPU pool holds, which is enough for the sample.
  6. Under Infrastructure Configuration, choose a CPU family under Compute Family and its smallest Plan. Choose On-Demand under Billing Plan, and click Add Pool.
  7. Under Network Settings, choose a VPC. If you have none, click Create New to make one without leaving the form.
  8. Open Advanced Settings and choose the security group that allows TCP port 6443 and UDP port 8472.
  9. The Summary panel adds up the cost as you choose. Check it, and click Create Cluster.

Back on the list, with Kubernetes cluster created successfully. Please wait for 5-10 minutes to configure., your cluster reads Creating. Wait until it reads Running. If it still reads Creating after 80 minutes, see Troubleshooting Kubernetes.

  1. In the list, click your cluster’s name, and stay on its Cluster Details tab.

  2. In the Kubeconfig row, click the download button. The file is saved as <cluster-name>-kubeconfig.yaml, where <cluster-name> is your cluster’s name.

  3. Move the file to a folder of its own, such as ~/.kube/, and use that path. On Windows, use $HOME\.kube\.

  4. Point kubectl at the file for this terminal session:

    export KUBECONFIG="$HOME/.kube/<cluster-name>-kubeconfig.yaml"

    On Windows PowerShell, run this instead:

    $env:KUBECONFIG = "$HOME\.kube\<cluster-name>-kubeconfig.yaml"
  5. List the cluster’s nodes:

    kubectl get nodes

kubectl lists the cluster’s nodes, one row each, like this:

NAME STATUS ROLES AGE VERSION
<node-name> Ready <roles> 5m v<version>

A node that reads Ready can run pods. If the command times out, see Troubleshooting Kubernetes.

Create a Deployment that runs two copies of the NGINX web server:

kubectl create deployment hello --image=nginx --replicas=2
kubectl get pods

Both pods read Running once their image has been pulled:

NAME READY STATUS RESTARTS AGE
hello-<pod-id> 1/1 Running 0 30s
hello-<other-pod-id> 1/1 Running 0 30s

A LoadBalancer service gets its external IP from the cluster’s LB IP Pool, one IP per service, so attach a public service IP to the pool first.

  1. On your cluster’s page, open the LB IP Pool tab.

  2. If the tab says Currently no reserved Service IP is available, click Click here to reserve one. A public service IP counts toward your account’s reserved-IP limit, and reserving one needs enough infra credits.

  3. When the tab says Currently no Service IP attached, click Click here. Attach Public IP opens.

  4. Under Select IP, choose the IP, and click Attach IP. The IP is listed under Service IP.

  5. Create a LoadBalancer service for the Deployment, and watch it get its address:

    kubectl expose deployment hello --type=LoadBalancer --port=80
    kubectl get service hello --watch

kubectl prints a new line each time the service changes, <pending> first, then the IP:

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello LoadBalancer <cluster-ip> <pending> 80:<port>/TCP 2s
hello LoadBalancer <cluster-ip> <external-ip> 80:<port>/TCP 5s

When EXTERNAL-IP changes from <pending> to the public service IP you attached, press Ctrl+C and open http://<external-ip> in a browser, where <external-ip> is that address. The NGINX welcome page opens. Your first application is running on your cluster.

A public service IP is billed from when you reserve it until you release it. For current prices, see E2E’s pricing page.

(Optional) Run images from a private registry

Section titled “(Optional) Run images from a private registry”

To run images from E2E’s Container Registry, see Pull images from a Kubernetes pod. For another private registry, store its credentials in a secret with kubectl create secret docker-registry, and list the secret under the pod’s image pull secrets.

When you have finished trying the sample, remove it so the public service IP is free again:

kubectl delete service hello
kubectl delete deployment hello

The public service IP stays reserved, and billed, until you release it. To stop the charge, detach it on the LB IP Pool tab and delete it; see Delete a reserved IP. To remove the whole cluster, see Delete a cluster.