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.
Create the cluster
Section titled “Create the cluster”- In MyAccount, under Compute, click Kubernetes, and click Create New Cluster. Create Kubernetes Cluster opens.
- Cluster Name is filled in for you. Keep it, or enter your own name of up to 50 letters, digits, hyphens, and underscores.
- Choose a Kubernetes Version that your tools support. The cluster keeps its version and its name for its whole life.
- Under Plan, select the On-Demand card, which bills the master node by the minute.
- 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.
- Under Infrastructure Configuration, choose a CPU family under Compute Family and its smallest Plan. Choose On-Demand under Billing Plan, and click Add Pool.
- Under Network Settings, choose a VPC. If you have none, click Create New to make one without leaving the form.
- Open Advanced Settings and choose the security group that allows TCP port 6443 and UDP port 8472.
- 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.
Download the kubeconfig
Section titled “Download the kubeconfig”-
In the list, click your cluster’s name, and stay on its Cluster Details tab.
-
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. -
Move the file to a folder of its own, such as
~/.kube/, and use that path. On Windows, use$HOME\.kube\. -
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" -
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.
Deploy a sample application
Section titled “Deploy a sample application”Create a Deployment that runs two copies of the NGINX web server:
kubectl create deployment hello --image=nginx --replicas=2kubectl get podsBoth pods read Running once their image has been pulled:
NAME READY STATUS RESTARTS AGEhello-<pod-id> 1/1 Running 0 30shello-<other-pod-id> 1/1 Running 0 30sExpose it on a public IP
Section titled “Expose it on a public IP”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.
-
On your cluster’s page, open the LB IP Pool tab.
-
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.
-
When the tab says Currently no Service IP attached, click Click here. Attach Public IP opens.
-
Under Select IP, choose the IP, and click Attach IP. The IP is listed under Service IP.
-
Create a LoadBalancer service for the Deployment, and watch it get its address:
kubectl expose deployment hello --type=LoadBalancer --port=80kubectl 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) AGEhello LoadBalancer <cluster-ip> <pending> 80:<port>/TCP 2shello LoadBalancer <cluster-ip> <external-ip> 80:<port>/TCP 5sWhen 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.
Clean up
Section titled “Clean up”When you have finished trying the sample, remove it so the public service IP is free again:
kubectl delete service hellokubectl delete deployment helloThe 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.
What to do next
Section titled “What to do next”- Create a cluster: every choice on the create form, including committed billing, autoscaling pools, subnets, and encryption.
- Connect to a cluster with kubectl: keep the kubeconfig set for every session, and open the Kubernetes Dashboard.
- Expose a service with a load balancer: write the service as a manifest, and give it a private LB IP for traffic inside the VPC.
- Use persistent volumes: keep your application’s data when its pods restart.
- Troubleshooting Kubernetes and Kubernetes FAQ: fixes and short answers when something does not go as expected.