Bootstrap FreeKB - Kubernetes - Getting Started with kubectl
Kubernetes - Getting Started with kubectl

Updated:   |  Kubernetes articles

The kubectl command is used to perform a variety of tasks, such as displaying the nodes in your cluster, creating a secret, viewing logs, and the list goes on. First and foremost, you may need to download and install the kubectl CLI.

For example, the following curl command can be used to download version 1.23.6 of kubectl to your present working directory.

curl --location --remote-name https://storage.googleapis.com/kubernetes-release/release/v1.23.6/bin/linux/amd64/kubectl

 

The aws eks list-clusters command can be used to list your Elastic Kubernetes Service (EKS).

~]$ aws eks list-clusters
{
    "clusters": [
        "my-cluster"
    ]
}

 

And then the aws eks update-kubeconfig command can be used to create or update your hidden .kube/config file. By default, the hidden .kube config file will be created at /home/your_username/.kube/config.

~]$ aws eks update-kubeconfig --name my-cluster
Added new context arn:aws:eks:us-east-1:123456789012:cluster/my-cluster to /home/john.doe/.kube/config

 

Underneath the hood, the aws eks update-kubeconfig command creates or updates the kube config file, and the kube config file uses the aws eks get-token command to get an authentication token that is used to authenticate to your Kubernetes cluster. This would be just like using the aws eks get-token command to get an authentication token.

~]$ aws eks get-token --cluster-name my-cluster
{
 "kind": "ExecCredential",
 "apiVersion": "client.authentication.k8s.io/v1alpha1",
 "spec": {},
 "status": {
   "expirationTimestamp": "2023-10-23T20:29:08Z",
   "token": "k8s-aws-v1.aHR0....zljYw"
  }
}

 

And then including the --token option in kubectl.

kubectl get pods --token <token goes here>

 

You can now try to use kubectl. I would first try the kubectl version command. I wouldn't be surprised if you get a warning that the version of kubectl does not match your Kubernetes version.

]$ kubectl version
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.6", GitCommit:"ad3338546da947756e8a88aa6822e9c11e7eac22", GitTreeState:"clean", BuildDate:"2022-04-14T08:49:13Z", GoVersion:"go1.17.9", Compiler:"gc", Platform:"linux/amd64"}

Server Version: version.Info{Major:"1", Minor:"27+", GitVersion:"v1.27.6-eks-f8587cb", GitCommit:"b6911bf9eade7d8ca7dd82af5e80626965829947", GitTreeState:"clean", BuildDate:"2023-09-18T22:12:19Z", GoVersion:"go1.20.8", Compiler:"gc", Platform:"linux/amd64"}

WARNING: version difference between client (1.23) and server (1.27) exceeds the supported minor version skew of +/-1

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 62b14d in the box below so that we can be sure you are a human.