Bobcares

AWS EKS Setup Kubectl: How to?

by | Aug 20, 2022

Let us take a closer look at to AWS EKS setup kubectl command line in detail. With the support of our AWS Support services, at Bobcraes we can give you complete and detailed support on how to set it up.

Kubectl

aws eks setup kubectl

Kubectl is a command-line utility for interacting with the Kubernetes API server. Many operating system package managers provide the kubectl binary. Using a package manager for installation is frequently faster than downloading and installing manually.

There are two methods for creating or updating the kubeconfig file. Generate or update a kubeconfig file quickly with the AWS CLI update-kubeconfig command, or create a kubeconfig file manually with the AWS CLI or the aws-iam-authenticator.

Create and setup kubectl file

To create kubeconfig file with the AWS CLI:

  1. Ensure that version 1.25.35 or 2.7.13 or later is installed.
  2. Create or edit the cluster’s kubeconfig file. And change the user values.

Note that by default, the resultant configuration file is produced in the home directory at the default kubeconfig path (.kube) or merged with an existing config file at that location. Use the —kubeconfig option to provide a different route.

Use the —role-am option to specify an IAM role ARN to use for authentication when issuing kubectl commands. Otherwise, the default AWS CLI or SDK credential chain uses the IAM entity. To view the default AWS CLI or SDK, use the aws sts get-caller-identity command.

aws eks update-kubeconfig --region region-code --name my-cluster

Confirm the settings. kubectl get svc

The example output is as follows:

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/kubernetes ClusterIP 10.100.0.1 443/TCP 1m

Create kubeconfig manually

To manually build the kubeconfig file for aws eks setup kubectl, follow the procedures outlined below:

Firstly, replace the user values with the values for a few variables before running the modified instructions.

export region_code=region-code
export cluster_name=my-cluster
export account_id=111122223333

cluster_endpoint=$(aws eks describe-cluster \
--region $region_code \
--name $cluster_name \
--query "cluster.endpoint" \
--output text)

Retrieve and store the Base64-encoded certificate data necessary to connect with the cluster in a variable.

certificate_data=$(aws eks describe-cluster \
--region $region_code \
--name $cluster_name \
--query "cluster.certificateAuthority.data" \
--output text

If it does not already exist, create the usual /.kube directory.

mkdir -p ~/.kube

To generate the config file in the /.kube directory, run the command for the desired client token method (AWS CLI or AWS IAM authenticator for Kubernetes). By amending the command to include the following, you can provide the following before performing one of the commands:

  1. Remove the # at the beginning of the lines under args: for an IAM role. To execute cluster operations instead of the default AWS credential provider chain, replace my-role with the name of the IAM role.
  2. AWS CLI profile name – Remove the # at the beginning of the env: line and the # at the beginning of the lines after it. Replace aws-profile with the name of the to-be-used profile. If the profile is not available, then it will use the default profile.

Requirements for AWS eks setup kubectl

The device must have AWS CLI version 1.16.156 or later installed.

#!/bin/bash
read -r -d '' KUBECONFIG < ~/.kube/config

Set the KUBECONFIG environment variable to the file location so that kubectl knows where to look for the cluster configuration. Check that the conditions for an easy AWS eks setup kubectl process are met:

  1. For macOS or Linux Bash shells:

    export KUBECONFIG=$KUBECONFIG:~/.kube/config

  2. For Windows PowerShell:

    $ENV:KUBECONFIG="{0};{1}" -f $ENV:KUBECONFIG, "$ENV:userprofile\.kube\config"

    (Optional) Include the settings in the shell initialization file so that it is available when opening a shell.

  3. For Bash shells on macOS:

    echo 'export KUBECONFIG=$KUBECONFIG:~/.kube/config' >> ~/.bash_profile

  4. For AWS eks setup Kubert for the Bash shells on Linux:

    echo 'export KUBECONFIG=$KUBECONFIG:~/.kube/config' >> ~/.bashrc

  5. For PowerShell on Windows:

    [System.Environment]::SetEnvironmentVariable('KUBECONFIG', $ENV:KUBECONFIG, 'Machine')

Test the configurations by typing in the code: kubectl get svc. This is the final step in the AWS eks setup kubectl.

[Need assistance with similar queries? We are here to help]

Conclusion

To conclude, aws eks setup kubectl command line allows access to the Kubernetes API server. Many operating system package managers contain the kubectl binary.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.