k8s-helper-cli 0.2.1__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: k8s-helper-cli
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: A simplified Python wrapper for common Kubernetes operations
5
5
  Author-email: Harshit Chatterjee <harshitchatterjee50@gmail.com>
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "k8s-helper-cli"
3
- version = "0.2.1"
3
+ version = "0.2.3"
4
4
  description = "A simplified Python wrapper for common Kubernetes operations"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -20,7 +20,7 @@ from .utils import (
20
20
  create_service_manifest
21
21
  )
22
22
 
23
- __version__ = "0.2.1"
23
+ __version__ = "0.2.3"
24
24
  __author__ = "Harshit Chatterjee"
25
25
  __email__ = "harshitchatterjee50@gmail.com"
26
26
 
@@ -691,7 +691,16 @@ def create_eks_cluster(
691
691
  console.print(f"💻 Instance types: {instance_type_list}")
692
692
  console.print(f"📊 Scaling: {min_size}-{max_size} nodes (desired: {desired_size})")
693
693
 
694
- with console.status("Creating EKS cluster..."):
694
+ # Show what will be created
695
+ console.print("\n🔧 EKS Requirements:")
696
+ console.print(" • IAM roles for cluster and node groups")
697
+ console.print(" • VPC subnets in at least 2 availability zones")
698
+ console.print(" • Security groups for cluster communication")
699
+ console.print(" • EKS cluster control plane")
700
+ if node_group:
701
+ console.print(" • Managed node group with EC2 instances")
702
+
703
+ with console.status("Creating EKS cluster and required resources..."):
695
704
  cluster_info = eks_client.create_cluster(
696
705
  cluster_name=name,
697
706
  version=version,
@@ -704,6 +713,9 @@ def create_eks_cluster(
704
713
  console.print(f"📋 Cluster ARN: {cluster_info['cluster_arn']}")
705
714
  console.print(f"🕐 Created at: {cluster_info['created_at']}")
706
715
 
716
+ if 'subnets' in cluster_info:
717
+ console.print(f"🌐 Subnets: {cluster_info['subnets']}")
718
+
707
719
  if wait:
708
720
  console.print("⏳ Waiting for cluster to become active...")
709
721
  with console.status("Waiting for cluster to be ready..."):
@@ -713,13 +725,38 @@ def create_eks_cluster(
713
725
  # Show cluster status
714
726
  status = eks_client.get_cluster_status(name)
715
727
  console.print(f"🔗 Endpoint: {status['endpoint']}")
728
+
729
+ # Show next steps
730
+ console.print(f"\n🚀 Next steps:")
731
+ console.print(f" 1. Configure kubectl: aws eks update-kubeconfig --name {name} --region {region}")
732
+ console.print(f" 2. Verify connection: kubectl get svc")
733
+ console.print(f" 3. Deploy applications: k8s-helper apply <app-name> <image>")
716
734
  else:
717
735
  console.print("❌ Timeout waiting for cluster to become active")
718
736
  else:
719
- console.print("💡 Use 'aws eks update-kubeconfig --name {name} --region {region}' to configure kubectl")
737
+ console.print(f"💡 Use 'aws eks update-kubeconfig --name {name} --region {region}' to configure kubectl")
720
738
 
721
739
  except Exception as e:
722
- console.print(f"❌ Failed to create EKS cluster: {e}")
740
+ error_message = str(e)
741
+ console.print(f"❌ Failed to create EKS cluster: {error_message}")
742
+
743
+ # Provide helpful guidance based on error type
744
+ if "Need at least 2 subnets" in error_message:
745
+ console.print("\n🛠️ Troubleshooting:")
746
+ console.print(" • EKS requires subnets in at least 2 availability zones")
747
+ console.print(" • Check your VPC configuration in the AWS Console")
748
+ console.print(" • Ensure you have subnets in different AZs")
749
+ console.print(" • The tool will attempt to create subnets if none exist")
750
+ elif "credentials not found" in error_message:
751
+ console.print("\n🛠️ Troubleshooting:")
752
+ console.print(" • Configure AWS credentials: aws configure")
753
+ console.print(" • Or set environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY")
754
+ console.print(" • Ensure you have EKS permissions")
755
+ elif "VPC" in error_message:
756
+ console.print("\n🛠️ Troubleshooting:")
757
+ console.print(" • Check your VPC configuration")
758
+ console.print(" • Ensure you have a default VPC or create one")
759
+ console.print(" • Verify subnet CIDR ranges don't overlap")
723
760
 
724
761
 
725
762
  # ======================
@@ -74,12 +74,16 @@ class EKSClient:
74
74
  resourcesVpcConfig={
75
75
  'subnetIds': subnets,
76
76
  'securityGroupIds': security_groups or [],
77
- 'endpointConfigPublic': True,
78
- 'endpointConfigPrivate': True
77
+ 'endpointPublicAccess': True,
78
+ 'endpointPrivateAccess': True
79
79
  },
80
80
  logging={
81
- 'enable': True,
82
- 'types': ['api', 'audit', 'authenticator', 'controllerManager', 'scheduler']
81
+ 'clusterLogging': [
82
+ {
83
+ 'types': ['api', 'audit', 'authenticator', 'controllerManager', 'scheduler'],
84
+ 'enabled': True
85
+ }
86
+ ]
83
87
  }
84
88
  )
85
89
 
@@ -106,22 +110,110 @@ class EKSClient:
106
110
  raise Exception(f"Failed to create EKS cluster: {e}")
107
111
 
108
112
  def _get_default_subnets(self) -> List[str]:
109
- """Get default subnets for EKS cluster"""
113
+ """Get default subnets for EKS cluster from different AZs"""
110
114
  try:
111
115
  response = self.ec2_client.describe_subnets()
112
- subnets = []
116
+
117
+ # Group subnets by availability zone
118
+ subnets_by_az = {}
113
119
  for subnet in response['Subnets']:
114
120
  if subnet['State'] == 'available':
115
- subnets.append(subnet['SubnetId'])
121
+ az = subnet['AvailabilityZone']
122
+ if az not in subnets_by_az:
123
+ subnets_by_az[az] = []
124
+ subnets_by_az[az].append(subnet['SubnetId'])
125
+
126
+ # Get at least 2 subnets from different AZs
127
+ selected_subnets = []
128
+ for az, subnet_ids in subnets_by_az.items():
129
+ if len(selected_subnets) < 2:
130
+ selected_subnets.append(subnet_ids[0]) # Take first subnet from each AZ
116
131
 
117
- if len(subnets) < 2:
118
- raise Exception("Need at least 2 subnets for EKS cluster")
132
+ if len(selected_subnets) < 2:
133
+ # If we don't have subnets in 2 different AZs, let's create them
134
+ selected_subnets = self._create_default_vpc_subnets()
119
135
 
120
- return subnets[:2] # Return first 2 available subnets
136
+ return selected_subnets
121
137
 
122
138
  except ClientError as e:
123
139
  raise Exception(f"Failed to get default subnets: {e}")
124
140
 
141
+ def _create_default_vpc_subnets(self) -> List[str]:
142
+ """Create default VPC and subnets for EKS if none exist"""
143
+ try:
144
+ # Get default VPC
145
+ vpcs = self.ec2_client.describe_vpcs(Filters=[{'Name': 'isDefault', 'Values': ['true']}])
146
+ if not vpcs['Vpcs']:
147
+ raise Exception("No default VPC found. Please create subnets manually or set up a VPC.")
148
+
149
+ vpc_id = vpcs['Vpcs'][0]['VpcId']
150
+
151
+ # Get available AZs
152
+ azs = self.ec2_client.describe_availability_zones()
153
+ if len(azs['AvailabilityZones']) < 2:
154
+ raise Exception("Need at least 2 availability zones for EKS cluster")
155
+
156
+ # Create subnets in first 2 AZs
157
+ subnet_ids = []
158
+ for i, az in enumerate(azs['AvailabilityZones'][:2]):
159
+ cidr = f"172.31.{i * 16}.0/20" # Create non-overlapping CIDR blocks
160
+
161
+ try:
162
+ response = self.ec2_client.create_subnet(
163
+ VpcId=vpc_id,
164
+ CidrBlock=cidr,
165
+ AvailabilityZone=az['ZoneName']
166
+ )
167
+ subnet_id = response['Subnet']['SubnetId']
168
+ subnet_ids.append(subnet_id)
169
+
170
+ # Enable auto-assign public IP
171
+ self.ec2_client.modify_subnet_attribute(
172
+ SubnetId=subnet_id,
173
+ MapPublicIpOnLaunch={'Value': True}
174
+ )
175
+
176
+ # Tag the subnet
177
+ self.ec2_client.create_tags(
178
+ Resources=[subnet_id],
179
+ Tags=[
180
+ {'Key': 'Name', 'Value': f'eks-subnet-{az["ZoneName"]}'},
181
+ {'Key': 'kubernetes.io/role/elb', 'Value': '1'}
182
+ ]
183
+ )
184
+
185
+ except ClientError as e:
186
+ if e.response['Error']['Code'] == 'InvalidVpc.Range':
187
+ # Try a different CIDR range
188
+ cidr = f"10.0.{i}.0/24"
189
+ response = self.ec2_client.create_subnet(
190
+ VpcId=vpc_id,
191
+ CidrBlock=cidr,
192
+ AvailabilityZone=az['ZoneName']
193
+ )
194
+ subnet_id = response['Subnet']['SubnetId']
195
+ subnet_ids.append(subnet_id)
196
+
197
+ # Enable auto-assign public IP
198
+ self.ec2_client.modify_subnet_attribute(
199
+ SubnetId=subnet_id,
200
+ MapPublicIpOnLaunch={'Value': True}
201
+ )
202
+
203
+ # Tag the subnet
204
+ self.ec2_client.create_tags(
205
+ Resources=[subnet_id],
206
+ Tags=[
207
+ {'Key': 'Name', 'Value': f'eks-subnet-{az["ZoneName"]}'},
208
+ {'Key': 'kubernetes.io/role/elb', 'Value': '1'}
209
+ ]
210
+ )
211
+
212
+ return subnet_ids
213
+
214
+ except ClientError as e:
215
+ raise Exception(f"Failed to create default subnets: {e}")
216
+
125
217
  def _create_or_get_cluster_role(self) -> str:
126
218
  """Create or get IAM role for EKS cluster"""
127
219
  role_name = "eks-cluster-role"
@@ -179,7 +271,7 @@ class EKSClient:
179
271
  'status': cluster['status'],
180
272
  'endpoint': cluster.get('endpoint', 'Not available'),
181
273
  'version': cluster['version'],
182
- 'platform_version': cluster['platformVersion'],
274
+ 'platform_version': cluster.get('platformVersion', 'Not available'),
183
275
  'created_at': cluster['createdAt'],
184
276
  'arn': cluster['arn']
185
277
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: k8s-helper-cli
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: A simplified Python wrapper for common Kubernetes operations
5
5
  Author-email: Harshit Chatterjee <harshitchatterjee50@gmail.com>
6
6
  License-Expression: MIT
File without changes
File without changes
File without changes