Interacting with Kubernetes
Once you have a Kubernetes cluster up and running, there are a number of ways to interact with it. This section will
go through a few of the most common ones, including the API, kubectl
, the Web UI, and Terraform.
API
Under the hood, any Kubernetes tool you use will be talking to the Kubernetes API. However, it’s relatively rare for you to have to make API calls directly (if you do have to, see the API client libraries), so let’s quickly move on to the other tools that build on top of the API.
kubectl
kubectl is the official command-line interface (CLI) for working with Kubernetes. For example, to deploy the training/webapp Docker container (a simple "Hello, World" webapp) and have it listen on port 5000, you could run:
kubectl run webapp \
--image=training/webapp:latest \
--port 5000 \
--generator=run-pod/v1
And to see the pods running in your cluster, you could run:
kubectl get pods
To be able to authenticate to different EKS clusters or as different users, you can create one or more kubectl
configuration files, which are typically called kubeconfig files (note, the files do not actually need to be called
kubeconfig
). In a kubeconfig file, you can define one or more contexts, where each context specifies a cluster to
connect to and a user to use for authentication. You can then use the kubectl config use-context
command to quickly
switch between contexts—and therefore, different clusters and users.
Web UI (Dashboard)
The Kubernetes Dashboard
The Kubernetes Dashboard is a web-based interface you can use to manage your Kubernetes cluster. The dashboard is not enabled by default in most Kubernetes distributions. Check out Deploying the Dashboard UI and Accessing the Dashboard UI for instructions.
Terraform
Terraform has a Kubernetes provider that allows you to write Terraform code that, under the hood, calls the Kubernetes API. This allows you to manage all your infrastructure—including your VPCs, databases, Kubernetes clusters, and Kubernetes services—using the same language and workflow. The downside is that the Terraform Kubernetes provider seems to lag behind considerably, and is missing some of the features you need for effectively working with Kubernetes, which often requires you to go outside of Terraform code anyway (e.g., execute a script).