Creating Kubernetes Cluster on AWS, Azure & GCP Cloud using CLI

Creating Kubernetes Cluster on AWS, Azure & GCP Cloud using CLI

In this article we will learn how to create Kubernetes Cluster on AWS, GCP and Azure.

Kubernetes, Google's container orchestration project that was open-sourced in 2014, swiftly gained momentum and eventually became a standard.?

No alt text provided for this image

Increasingly, businesses are utilizing various cloud vendors. We're moving toward multi-cloud deployments, which implies we're increasingly willing to deploy on multiple clouds. After all, one of the main advantages of Kubernetes is that it is (largely) cloud-agnostic once the cluster is up and running.

Kubernetes managed services are available from all major cloud providers.

While it is possible to install and manage Kubernetes on infrastructure that you manage, it is a time-consuming and complicated process. As a result, a number of companies have developed managed Kubernetes services that make provisioning and operating clusters much easier.

No alt text provided for this image

Amazon Elastic Container Service for Kubernetes (Amazon EKS)?makes it simple to install, manage, and scale Kubernetes-based containerized applications on AWS. To eliminate a single point of failure, Amazon EKS manages your Kubernetes management infrastructure across several AWS availability zones. You can utilize current tooling and plugins from partners and the Kubernetes community because Amazon EKS is certified Kubernetes conformant. Applications that run on any regular Kubernetes environment are fully compatible with Amazon EKS and can be quickly converted.

Google Kubernetes Engine (GKE)?was the first commercial Kubernetes as a Service offering, and it is a well-known and mature solution provided by Google, the company that created Kubernetes in the first place. In managed Kubernetes clusters, GKE allows you to deploy, manage, and monitor applications, services, and persistent storage. It comes with auto-scaling and Kubernetes auto-updates.

Azure Kubernetes Service (AKS) is an Azure-specific solution that optimizes the setup of popular open-source tools and technologies. It provides an open solution with portability for both user containers and user application settings.

We will create Kubernetes Cluster on AWS, GCP and Azure using CLI. For AWS we will use aws and eksctl cli. For GKE we will use gcloud cli and for AKS we will use az cli.

Amazon?Elastic Kubernetes Service?(EKS) using eksctl CLI -

Install eksctl

[prayag@panel ~]$ curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp

[prayag@panel ~]$ sudo mv /tmp/eksctl /usr/local/bin

[prayag@panel ~]$ which eksctl
/usr/local/bin/eksctl
[prayag@panel ~]$ eksctl version
0.110.0
[prayag@panel ~]$ . <(eksctl completion bash)
        

Install kubectl


[prayag@panel ~]$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"


[prayag@panel ~]$ sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
        

Create cluster


[prayag@panel ~]$ eksctl create cluster? --region us-west-2 --nodes 3 --nodes-min 1 --nodes-max 4 --name my-eks-cluster

2022-09-09 15:07:45 [?]? eksctl version 0.110.0
2022-09-09 15:07:45 [?]? using region us-west-2
2022-09-09 15:07:46 [?]? setting availability zones to [us-west-2d us-west-2c us-west-2b]
2022-09-09 15:07:46 [?]? subnets for us-west-2d - public:192.168.0.0/19 private:192.168.96.0/19
2022-09-09 15:07:46 [?]? subnets for us-west-2c - public:192.168.32.0/19 private:192.168.128.0/19
2022-09-09 15:07:46 [?]? subnets for us-west-2b - public:192.168.64.0/19 private:192.168.160.0/19
2022-09-09 15:07:46 [?]? nodegroup "ng-f977ac23" will use "" [AmazonLinux2/1.22]
2022-09-09 15:07:46 [?]? using Kubernetes version 1.22
2022-09-09 15:07:46 [?]? creating EKS cluster "my-eks-cluster" in "us-west-2" region with managed nodes
2022-09-09 15:07:46 [?]? will create 2 separate CloudFormation stacks for cluster itself and the initial managed nodegroup
2022-09-09 15:07:46 [?]? if you encounter any issues, check CloudFormation console or try 'eksctl utils describe-stacks --region=us-west-2 --cluster=my-eks-cluster'
2022-09-09 15:07:46 [?]? Kubernetes API endpoint access will use default of {publicAccess=true, privateAccess=false} for cluster "my-eks-cluster" in "us-west-2"
2022-09-09 15:07:46 [?]? CloudWatch logging will not be enabled for cluster "my-eks-cluster" in "us-west-2"
2022-09-09 15:07:46 [?]? you can enable it with 'eksctl utils update-cluster-logging --enable-types={SPECIFY-YOUR-LOG-TYPES-HERE (e.g. all)} --region=us-west-2 --cluster=my-eks-cluster'
2022-09-09 15:07:46 [?]
2 sequential tasks: { create cluster control plane "my-eks-cluster",
? ? 2 sequential sub-tasks: {
? ? ? ? wait for control plane to become ready,
? ? ? ? create managed nodegroup "ng-f977ac23",
? ? }
}
2022-09-09 15:07:46 [?]? building cluster stack "eksctl-my-eks-cluster-cluster"
2022-09-09 15:07:48 [?]? deploying stack "eksctl-my-eks-cluster-cluster"
2022-09-09 15:08:18 [?]? waiting for CloudFormation stack "eksctl-my-eks-cluster-cluster"
2022-09-09 15:08:48 [?]? waiting for CloudFormation stack "eksctl-my-eks-cluster-cluster"
2022-09-09 15:09:49 [?]? waiting for CloudFormation stack "eksctl-my-eks-cluster-cluster"
2022-09-09 15:10:50 [?]? waiting for CloudFormation stack "eksctl-my-eks-cluster-cluster"
.
.
.

2022-09-09 15:22:24 [?]? waiting for CloudFormation stack "eksctl-my-eks-cluster-nodegroup-ng-f977ac23"
2022-09-09 15:24:15 [?]? waiting for CloudFormation stack "eksctl-my-eks-cluster-nodegroup-ng-f977ac23"
2022-09-09 15:24:16 [?]? waiting for the control plane availability...
2022-09-09 15:24:19 [?]? saved kubeconfig as "/home/prayag/.kube/config"
2022-09-09 15:24:19 [?]? no tasks
2022-09-09 15:24:19 [?]? all EKS cluster resources for "my-eks-cluster" have been created
2022-09-09 15:24:20 [?]? nodegroup "ng-f977ac23" has 3 node(s)
2022-09-09 15:24:20 [?]? node "ip-192-168-23-147.us-west-2.compute.internal" is ready
2022-09-09 15:24:20 [?]? node "ip-192-168-50-217.us-west-2.compute.internal" is ready
2022-09-09 15:24:20 [?]? node "ip-192-168-68-139.us-west-2.compute.internal" is ready
2022-09-09 15:24:20 [?]? waiting for at least 1 node(s) to become ready in "ng-f977ac23"

2022-09-09 15:24:20 [?]? nodegroup "ng-f977ac23" has 3 node(s)
2022-09-09 15:24:20 [?]? node "ip-192-168-23-147.us-west-2.compute.internal" is ready
2022-09-09 15:24:20 [?]? node "ip-192-168-50-217.us-west-2.compute.internal" is ready
2022-09-09 15:24:20 [?]? node "ip-192-168-68-139.us-west-2.compute.internal" is ready

2022-09-09 15:24:24 [?]? kubectl command should work with "/home/prayag/.kube/config", try 'kubectl get nodes'
2022-09-09 15:24:24 [?]? EKS cluster "my-eks-cluster" in "us-west-2" region is ready
[prayag@panel ~]$

        

EKS info


[prayag@panel ~]$ eksctl info
eksctl version: 0.110.0
kubectl version: v1.25.0
OS: linux
[prayag@panel ~]$
        

EKS get cluster info


[prayag@panel ~]$ eksctl get clusters --region us-west-2
NAME? ? ? ? ? ? REGION? ? ? ? ? EKSCTL CREATED
my-eks-cluster? us-west-2? ? ? ?True
[prayag@panel ~]$
        

Kubernetes nodes info


[prayag@panel ~]$ kubectl get all
NAME? ? ? ? ? ? ? ? ?TYPE? ? ? ? CLUSTER-IP? ?EXTERNAL-IP? ?PORT(S)? ?AGE
service/kubernetes? ?ClusterIP? ?10.100.0.1? ?<none>? ? ? ? 443/TCP? ?18m
[prayag@panel ~]$ kubectl get nodes
NAME? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?STATUS? ?ROLES? ? AGE? ? ?VERSION
ip-192-168-23-147.us-west-2.compute.internal? ?Ready? ? <none>? ?9m22s? ?v1.22.12-eks-ba74326
ip-192-168-50-217.us-west-2.compute.internal? ?Ready? ? <none>? ?9m23s? ?v1.22.12-eks-ba74326
ip-192-168-68-139.us-west-2.compute.internal? ?Ready? ? <none>? ?9m24s? ?v1.22.12-eks-ba74326        

Delete cluster


[prayag@panel ~]$ eksctl delete cluster my-eks-cluster --region us-west-2

2022-09-09 15:35:15 [?]? deleting EKS cluster "my-eks-cluster"
2022-09-09 15:35:16 [?]? will drain 0 unmanaged nodegroup(s) in cluster "my-eks-cluster"
2022-09-09 15:35:16 [?]? starting parallel draining, max in-flight of 1
2022-09-09 15:35:17 [?]? deleted 0 Fargate profile(s)
2022-09-09 15:35:19 [?]? kubeconfig has been updated
2022-09-09 15:35:19 [?]? cleaning up AWS load balancers created by Kubernetes objects of Kind Service or Ingress
2022-09-09 15:35:21 [?]
2 sequential tasks: { delete nodegroup "ng-f977ac23", delete cluster control plane "my-eks-cluster" [async]
}
2022-09-09 15:35:22 [?]? will delete stack "eksctl-my-eks-cluster-nodegroup-ng-f977ac23"
2022-09-09 15:35:22 [?]? waiting for stack "eksctl-my-eks-cluster-nodegroup-ng-f977ac23" to get deleted
2022-09-09 15:35:22 [?]? waiting for CloudFormation stack "eksctl-my-eks-cluster-nodegroup-ng-f977ac23"

.
.
.

2022-09-09 15:44:37 [?]? waiting for CloudFormation stack "eksctl-my-eks-cluster-nodegroup-ng-f977ac23"
2022-09-09 15:44:38 [?]? will delete stack "eksctl-my-eks-cluster-cluster"
2022-09-09 15:44:38 [?]? all cluster resources were deleted
[prayag@panel ~]$
        

Google Kubernetes Engine (GKE) using gcloud CLI -

Install gcloud cli


$ curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-388.0.0-linux-x86_64.tar.gz
$ tar -xf google-cloud-cli-388.0.0-linux-x86.tar.gz
$./google-cloud-sdk/install.sh
$ which gcloud
$ gcloud init
        

Set region and zone


[prayag@panel ~]$ gcloud config set compute/region us-west1
Updated property [compute/region].

[prayag@panel ~]$ gcloud config get-value compute/region
us-west1
[prayag@panel ~]$


[prayag@panel ~]$ gcloud config set compute/zone us-west1-b
Updated property [compute/zone].
[prayag@panel ~]$ gcloud config get-value compute/zone
us-west1-b
        

Enable Kubernetes engine API


[prayag@panel ~]$ gcloud services enable container.googleapis.com
Operation "operations/acf.p2-974031097023-434976da-2108-400e-9dd3-3719095bc1f2" finished successfully.
[prayag@panel ~]$
        

Enable auth plugin


[prayag@panel ~]$ gcloud components install gke-gcloud-auth-plugin

Your current Google Cloud CLI version is: 401.0.0
Installing components from version: 401.0.0


┌────────────────────────────────────────────┐
│? ? These components will be installed.? ? ?│
├────────────────────────┬─────────┬─────────┤
│? ? ? ? ? Name? ? ? ? ? │ Version │? ?Size? │
├────────────────────────┼─────────┼─────────┤
│ gke-gcloud-auth-plugin │? ?0.3.0 │ 3.8 MiB │
└────────────────────────┴─────────┴─────────┘


For the latest full release notes, please visit:
? https://cloud.google.com/sdk/release_notes


Do you want to continue (Y/n)?? y


╔════════════════════════════════════════════════════════════╗
╠═ Creating update staging area? ? ? ? ? ? ? ? ?          ? ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gke-gcloud-auth-plugin? ? ? ? ?          ? ? ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Installing: gke-gcloud-auth-plugin? ? ? ? ?          ? ? ═╣
╠════════════════════════════════════════════════════════════╣
╠═ Creating backup and activating new installation          ═╣
╚════════════════════════════════════════════════════════════╝


Performing post processing steps...done.


Update done!


[prayag@panel ~]$
        

Create cluster


[prayag@panel ~]$ gcloud container clusters create my-gke-cluster --num-nodes 3
.
.


Creating cluster my-gke-cluster in us-west1-b... Cluster is being health-checked (master is healthy)...done.


Created [https://container.googleapis.com/v1/projects/gcp-cloud-devops-356219/zones/us-west1-b/clusters/my-gke-cluster].


To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/us-west1-b/my-gke-cluster?project=gcp-cloud-devops-356219
kubernetes/kubectl-auth-changes-in-gke
kubeconfig entry generated for my-gke-cluster.


NAME?  LOCATION? ? MASTER_VERSION? ?MASTER_IP? ? MACHINE_TYPE? NODE_VERSION? ? ?NUM_NODES? STATUS
my-gke-cluster? us-west1-b? 1.22.11-gke.400? 35.197.76.6? e2-medium? ? ?1.22.11-gke.400? 3? ? ? ? ? RUNNING

        

Kubeconfig entry


[prayag@panel ~]$ gcloud container clusters get-credentials my-gke-cluster
Fetching cluster endpoint and auth data.
kubeconfig entry generated for my-gke-cluster.
[prayag@panel ~]$
        

Get cluster details


[prayag@panel ~]$ gcloud container clusters list
NAME? ? ? ? ? ? LOCATION? ? MASTER_VERSION? ?MASTER_IP? ? MACHINE_TYPE? NODE_VERSION? ? ?NUM_NODES? STATUS
my-gke-cluster? us-west1-b? 1.22.11-gke.400? 35.197.76.6? e2-medium? ? ?1.22.11-gke.400? 3? ? ? ? ? RUNNING
[prayag@panel ~]$
        

Kubernetes nodes info


[prayag@panel ~]$ kubectl get all
NAME? ? ? ? ? ? ? ? ?TYPE? ? ? ? CLUSTER-IP? ?EXTERNAL-IP? ?PORT(S)? ?AGE
service/kubernetes? ?ClusterIP? ?10.124.0.1? ?<none>? ? ? ? 443/TCP? ?8m42s
[prayag@panel ~]$ kubectl get nodes
NAME? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? STATUS? ?ROLES? ? AGE? ? ?VERSION
gke-my-gke-cluster-default-pool-8c242d28-5jph? ?Ready? ? <none>? ?7m55s? ?v1.22.11-gke.400
gke-my-gke-cluster-default-pool-8c242d28-wzxk? ?Ready? ? <none>? ?7m55s? ?v1.22.11-gke.400
gke-my-gke-cluster-default-pool-8c242d28-zhgt? ?Ready? ? <none>? ?7m55s? ?v1.22.11-gke.400
[prayag@panel ~]$
        

Delete cluster


[prayag@panel ~]$ gcloud container clusters delete my-gke-cluster
The following clusters will be deleted.
?- [my-gke-cluster] in [us-west1-b]


Do you want to continue (Y/n)?? Y


Deleting cluster my-gke-cluster...done.
Deleted [https://container.googleapis.com/v1/projects/gcp-cloud-devops-356219/zones/us-west1-b/clusters/my-gke-cluster].
[prayag@panel ~]$
        

Azure Kubernetes Service?(AKS) using az CLI -

Install az cli


$ sudo yum -y install python3
$ curl -L https://aka.ms/InstallAzureCli | bash
$ which az

# configure  az cli , use az login
az login
        

Create Resource Group


[prayag@panel ~]$ az group create --name myAKSrg --location eastus

{
? "id": "/subscriptions/e4f94e9f-28ae-4e8c-ad41-41e9cc935ca9/resourceGroups/myAKSrg",
? "location": "eastus",
? "managedBy": null,
? "name": "myAKSrg",
? "properties": {
? ? "provisioningState": "Succeeded"
? },
? "tags": null,
? "type": "Microsoft.Resources/resourceGroups"
}
[prayag@panel ~]$

        

Create cluster


[prayag@panel ~]$ az aks create -g myAKSrg -n MyAKSCluster --node-count 2? --generate-ssh-keys

{
? "aadProfile": null,
? "addonProfiles": null,
? "agentPoolProfiles": [
? ? {
? ? ? "availabilityZones": null,
? ? ? "count": 2,
? ? ? "creationData": null,
? ? ? "currentOrchestratorVersion": "1.23.8",
? ? ? "enableAutoScaling": false,
? ? ? "enableEncryptionAtHost": false,
? ? ? "enableFips": false,
? ? ? "enableNodePublicIp": false,
? ? ? "enableUltraSsd": false,
? ? ? "gpuInstanceProfile": null,
? ? ? "kubeletConfig": null,
? ? ? "kubeletDiskType": "OS",
? ? ? "linuxOsConfig": null,
? ? ? "maxCount": null,
? ? ? "maxPods": 110,
? ? ? "minCount": null,
? ? ? "mode": "System",
? ? ? "name": "nodepool1",
? ? ? "nodeImageVersion": "AKSUbuntu-1804gen2containerd-2022.08.23",
? ? ? "nodeLabels": null,
? ? ? "nodePublicIpPrefixId": null,
? ? ? "nodeTaints": null,
? ? ? "orchestratorVersion": "1.23.8",
? ? ? "osDiskSizeGb": 128,
? ? ? "osDiskType": "Managed",
? ? ? "osSku": "Ubuntu",
? ? ? "osType": "Linux",
? ? ? "podSubnetId": null,
? ? ? "powerState": {
? ? ? ? "code": "Running"
? ? ? },
? ? ? "provisioningState": "Succeeded",
? ? ? "proximityPlacementGroupId": null,
? ? ? "scaleDownMode": null,
? ? ? "scaleSetEvictionPolicy": null,
? ? ? "scaleSetPriority": null,
? ? ? "spotMaxPrice": null,
? ? ? "tags": null,
? ? ? "type": "VirtualMachineScaleSets",
? ? ? "upgradeSettings": {
? ? ? ? "maxSurge": null
? ? ? },
? ? ? "vmSize": "Standard_DS2_v2",
? ? ? "vnetSubnetId": null,
? ? ? "workloadRuntime": null
? ? }
    
    .
    .
    .
    .

? ? },
? ? "loadBalancerSku": "Standard",
? ? "natGatewayProfile": null,
? ? "networkMode": null,
? ? "networkPlugin": "kubenet",
? ? "networkPolicy": null,
? ? "outboundType": "loadBalancer",
? ? "podCidr": "10.244.0.0/16",
? ? "podCidrs": [
? ? ? "10.244.0.0/16"
? ? ],
? ? "serviceCidr": "10.0.0.0/16",
? ? "serviceCidrs": [
? ? ? "10.0.0.0/16"
? ? ]
? },
? "nodeResourceGroup": "MC_myAKSrg_MyAKSCluster_eastus",
? "podIdentityProfile": null,
? "powerState": {
? ? "code": "Running"
? },
? "privateFqdn": null,
? "privateLinkResources": null,
? "provisioningState": "Succeeded",
? "publicNetworkAccess": null,
? "resourceGroup": "myAKSrg",
? "securityProfile": {
? ? "azureDefender": null
? },
? "servicePrincipalProfile": {
? ? "clientId": "msi",
? ? "secret": null
? },
? "sku": {
? ? "name": "Basic",
? ? "tier": "Free"
? },
? "storageProfile": {
? ? "diskCsiDriver": {
? ? ? "enabled": true
? ? },
? ? "fileCsiDriver": {
? ? ? "enabled": true
? ? },
? ? "snapshotController": {
? ? ? "enabled": true
? ? }
? },
? "systemData": null,
? "tags": null,
? "type": "Microsoft.ContainerService/ManagedClusters",
? "windowsProfile": null
}
[prayag@panel ~]$


        

Kubeconfig entry


[prayag@panel ~]$ az aks get-credentials --resource-group myAKSrg --name MyAKSCluster
Merged "MyAKSCluster" as current context in /home/prayag/.kube/config
[prayag@panel ~]$
        

Get node details


[prayag@panel ~]$ kubectl get all
NAME? ? ? ? ? ? ? ? ?TYPE? ? ? ? CLUSTER-IP? ?EXTERNAL-IP? ?PORT(S)? ?AGE
service/kubernetes? ?ClusterIP? ?10.0.0.1? ? ?<none>? ? ? ? 443/TCP? ?8m39s
[prayag@panel ~]$ kubectl get nodes
NAME? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? STATUS? ?ROLES? ?AGE? ? ?VERSION
aks-nodepool1-34601530-vmss000000? ?Ready? ? agent? ?7m30s? ?v1.23.8
aks-nodepool1-34601530-vmss000001? ?Ready? ? agent? ?7m23s? ?v1.23.8
[prayag@panel ~]$
        

Delete cluster


[prayag@panel ~]$ az aks delete --resource-group myAKSrg --name MyAKSCluster
Are you sure you want to perform this operation? (y/n): y
[prayag@panel ~]$
        


I hope you found this to be useful in some way. I’ll be back with some more interesting new Kubernetes, Cloud and Devops articles soon.

Using CLI (I call it simpler - bash (WInBash ??) is much simpler than window UI

要查看或添加评论,请登录

社区洞察

其他会员也浏览了