Skip to content

Commit

Permalink
docs: Update docs and rename package to eksupgrade (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbeacom authored Jan 31, 2023
1 parent 7f2a977 commit d6b3f41
Show file tree
Hide file tree
Showing 25 changed files with 84 additions and 91 deletions.
110 changes: 42 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@


<div align="center">
<h1> Amazon EKS One Click Upgrade </h1>
</div>

<!--
## EKS one click upgrade -->
# Amazon EKS Upgrade Utility

<p align="center">
<a href="">
<img src="https://forthebadge.com/images/badges/open-source.svg" alt="Opensource eks" style="vertical-align:top; margin:4px">
</a>
<a href="">
<img src="http://ForTheBadge.com/images/badges/built-with-love.svg" alt="Eks one click" style="vertical-align:top; margin:4px">
<img src="https://ForTheBadge.com/images/badges/built-with-love.svg" alt="Eks one click" style="vertical-align:top; margin:4px">
</a>
<a href="">
<img src="http://ForTheBadge.com/images/badges/made-with-python.svg" alt="kubernetes python" style="vertical-align:top; margin:4px">
<img src="https://ForTheBadge.com/images/badges/made-with-python.svg" alt="kubernetes python" style="vertical-align:top; margin:4px">
</a>
</p>

Expand All @@ -25,7 +18,8 @@ Working with EKS starts with creating a cluster and an Amazon EKS cluster consis
1. Amazon EKS control plane
2. Amazon EKS nodes that are registered with the control plane

The current process of EKS cluster upgrade includes
The current process of EKS cluster upgrade includes:

1. Check the Kubernetes object compatibility with regards to API specific Changes
2. Check the version of Core Kubernetes Components and do changes as per the changes required in the newer
version which is compatible with the targeted version.
Expand Down Expand Up @@ -66,41 +60,39 @@ After the pre-flight check is completed for the cluster an email is generated su
- Launch new nodes with upgraded version and wait until they require ready status for next step.
- Mark existing nodes as un-schedulable.
- If pod disruption budget (PDB) is present then check for force eviction flag (--force) which is given by user, only then evit the pods or continue with the flow.


### Objective
### Objective

1. **To upgrade the cluster in one click** : There are many steps involved in updating a cluster and our main objective is to automate all the steps involved in EKS Cluster Upgradation to one click.
2. **To reduce manual effort and time** : To update an EKS cluster , customers have to manually perform every step which is quite time taking and also a hectic task so, our objective is to reduce that manual intervention and also to save customer’s time.

### Architecture

This is the architecture of EKS One Click Upgrade:
<p align="center">
<img src="./Images/architecture.png" height="600px"/>
</p>


### Components used

![Technologies Used ](./Images/technologies-used.png)

### Workflow
Once the user executes the python script, a pre-flight check is initiated where multiple parameters and versions associated with the cluster are verified. If this check is performed successfully, then the upgrade workflow will be initiated and the cluster along with its components will be upgraded to the target version. After the upgradation process, a final check is done and an email is generated summarizing the details of cluster.

Once the user executes the python script, a pre-flight check is initiated where multiple parameters and versions associated with the cluster are verified. If this check is performed successfully, then the upgrade workflow will be initiated and the cluster along with its components will be upgraded to the target version. After the upgradation process, a final check is done and an email is generated summarizing the details of cluster.

<p align="center">
<img src="./Images/workflow.png"/>
</p>

### How to use EKS One Click Upgrade via CLI


```zsh

$ aws eks update-kubeconfig --name eks-cluster-name --region aws-region
$ kubectl edit configmap aws-auth -n kube-system

Add the IAM user to mapUsers. For example:
# Add the IAM user to mapUsers. For example:
mapUsers: |
- userarn: arn:aws:iam::XXXXXXXXXXXX:user/testuser
username: testuser
Expand All @@ -112,18 +104,17 @@ mapRoles: |
username: testrole
groups:
- system:masters

```

**Roles and Policies required**
### Roles and Policies required

In order to proceed with the upgrade and preflight workflow for your EKS cluster, below mentioned permissions are required as part of the IAM user being used to complete with the process. Below mentioned IAM policy can be used to attach to a user in order to grant access to required AWS service and related actions to complete the processs for eks-one-click upgrade

For more information related to steps on how to create and attach IAM policy, you can follow the below mentioned steps in AWS Documentation
For more information related to steps on how to create and attach IAM policy, you can follow the below mentioned steps in AWS Documentation

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-and-attach-iam-policy.html
[https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-and-attach-iam-policy.html](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-and-attach-iam-policy.html)

```json
```json
{
"Version": "2012-10-17",
"Statement": [
Expand Down Expand Up @@ -183,111 +174,94 @@ https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-
}
```

**Packages Required**

```bash
$ pip3 install boto3
$ pip3 install kubernetes
```
### Folder Structure

**Folder Structure**

```
eksupdater/
```bash
eks-upgrade/
├── src/
│ ├── s3Files/
│ ├── S3Files/
│ ├── __init__.py
│ ├── boto_aws.py
│ ├── eks_get_image_type.py
│ ├── eksctlfinal.py
── ekslogs.py
── ekslogs.py
│ ├── k8s_client.py
── latest_ami.py
── latest_ami.py
│ ├── preflight_module.py
│ └── self_managed.py
├── eks_updater.py
└── installer.py
├── __init__.py
├── cli.py
└── starter.py
```

## Installation

```zsh
pip install eksupgrade
```

**Running the script**
## Usage

```zsh

To Get Help Use [-h]

Usage :

eks-one-click-upgrade % python3 eks_updater.py -h

usage: eks_updater.py [-h] [--pass_vpc] [--max_retry MAX_RETRY] [--force]
[--eksctl] [--preflight] [--email EMAIL]
name version region

eks-one-click-upgrade % eksupgrade -h

usage: eksupgrade [-h] [--pass_vpc] [--max_retry MAX_RETRY] [--force]
[--eksctl] [--preflight] [--email EMAIL]
name version region

To Receive Email Report Use [ --email]

Usage :

eks-one-click-upgrade % python3 eks_updater.py Cluster_Name new_Version aws_Region --email [email protected]



eks-one-click-upgrade % eksupgrade Cluster_Name new_Version aws_Region --email [email protected]

To Skip The upgrade and if you only want to perform preflight check [ --preflight ]

Usage :

eks-one-click-upgrade % python3 eks_updater.py Cluster_Name new_Version aws_Region --email [email protected] --preflight




eks-one-click-upgrade % eksupgrade Cluster_Name new_Version aws_Region --email [email protected] --preflight

To Skip Vpc-cni Addon Upgrade use [ --pass_vpc ]

Usage :

eks-one-click-upgrade % python3 eks_updater.py Cluster_Name new_Version aws_Region --pass_vpc



eks-one-click-upgrade % eksupgrade Cluster_Name new_Version aws_Region --pass_vpc

Add Number of retry you want the script to peform by default it is 2 [ --max_retry ]

Usage :

eks-one-click-upgrade % python3 eks_updater.py Cluster_Name new_Version aws_Region --max_retry 5



eks-one-click-upgrade % eksupgrade Cluster_Name new_Version aws_Region --max_retry 5

To Utilize Force Pod Eviction when you Have Pdb (Pod disruption budget) [ --force]

Usage :

eks-one-click-upgrade % python3 eks_updater.py Cluster_Name new_Version aws_Region --pass_vpc
eks-one-click-upgrade % eksupgrade Cluster_Name new_Version aws_Region --pass_vpc

```
## Command Line Interface (CLI)
<p align="center">
<img src="./Images/CLI-1.png" height="800px"/>
<img src="./Images/CLI-2.png" height="600px"/>
</p>
## Security
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
## License
This library is licensed under the MIT-0 License. See the LICENSE file.
This library is licensed under the MIT-0 License. See the [LICENSE](LICENSE) file.
### 🤝 Contributing
* Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
* Please make sure to update tests as appropriate.
- Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
- Please make sure to update tests as appropriate.
Empty file removed eksupdate/src/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions eksupgrade/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Initialize the eksupgrade module.
Attributes:
__version__: The version of the eksupgrade module.
"""

__version__: str = "0.1.0"
19 changes: 10 additions & 9 deletions eksupdate/cli.py → eksupgrade/cli.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import argparse

from eksupdate.starter import main
from eksupgrade.starter import main


def entry():
example_text = """
example:
python3 eks_updater.py Name_Of_Cluster new_Version Region
eksupgrade name_of_cluster new_version region
Force Pod Eviction when you Have Pdb (Pod disruption budget):
Force pod eviction when you have PDB (Pod Disruption Budget):
-> python3 eks_updater.py Cluster_Name new_Version aws_Region --force
-> eksupgrade cluster_name new_version aws_region --force
Skip Vpc Cni Upgrade:
Skip VPC CNI upgrade:
-> python3 eks_updater.py Cluster_Name new_Version aws_Region --pass_vpc
-> eksupgrade cluster_name new_version aws_region --pass_vpc
Skip Upgrade Work Flow:
Skip upgrade workflow:
-> python3 eks_updater.py Cluster_Name new_Version aws_Region --preflight
-> eksupgrade cluster_name new_version aws_region --preflight
"""

"""
regions_list = [
"af-south-1",
"eu-north-1",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 6 additions & 3 deletions eksupdate/src/k8s_client.py → eksupgrade/src/k8s_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ def update_addons(cluster_name, version, vpcPass, regionName):
v1 = client.CoreV1Api()
api_instance = client.AppsV1Api()
rep = v1.list_namespaced_pod("kube-system")
add_on_dict = open("eksupdate/src/S3Files/version_dict.json", "r")
# TODO: Make this load safe. This file is never closed. Use context manager instead.
add_on_dict = open("eksupgrade/src/S3Files/version_dict.json", "r")
add_on_dict = json.load(add_on_dict)
old_pods_name = []

Expand Down Expand Up @@ -313,7 +314,8 @@ def update_addons(cluster_name, version, vpcPass, regionName):
name="coredns", namespace="kube-system", body=body, pretty=True
)
if vv <= 170:
coredns_yaml = open("eksupdate/src/S3Files/core-dns.yaml", "r")
# TODO: Make this load safe. This file is never closed. Use context manager instead.
coredns_yaml = open("eksupgrade/src/S3Files/core-dns.yaml", "r")
body = yaml.safe_load(coredns_yaml)
v1.patch_namespaced_config_map(name="coredns", namespace="kube-system", body=body)
flag_core = False
Expand Down Expand Up @@ -428,7 +430,8 @@ def update_addons(cluster_name, version, vpcPass, regionName):
elif "aws-node" in pod.metadata.name and image.split(":")[-1] != "v" + cni_new and not vpcPass:
print(pod.metadata.name, "Current Version = ", image.split(":")[-1], "Updating To = ", "v" + cni_new)
if flag_vpc:
vpc_cni_yaml = open("eksupdate/src/S3Files/vpc-cni.yaml", "r")
# TODO: Make this load safe. This file is never closed. Use context manager instead.
vpc_cni_yaml = open("eksupgrade/src/S3Files/vpc-cni.yaml", "r")
body = yaml.safe_load(vpc_cni_yaml)
body["spec"]["template"]["spec"]["containers"][0]["image"] = image.split(":")[0] + ":v" + cni_new
old = body["spec"]["template"]["spec"]["initContainers"][0]["image"]
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ def cluster_roles(preflight, log_details, errors, cluster_name, region, report,
# cluster_roles_list = s3.Object('eks-one-click-upgrade', 'cluster_roles.json')
# cluster_roles_list = cluster_roles_list.get()['Body'].read().decode('utf-8')
# cluster_roles_list = json.loads(cluster_roles_list)
# TODO: Make this load safe. This file is never closed. Use context manager instead.
f = open(
"eksupdate/src/S3Files/cluster_roles.json",
"eksupgrade/src/S3Files/cluster_roles.json",
)
cluster_roles_list = json.load(f)
# print(cluster_roles_list)
Expand Down Expand Up @@ -465,17 +466,19 @@ def addon_version(log_details, errors, cluster_name, region, cluster_details, re
# version_dict = json.loads(version_dict)
# print(version_dict)

# TODO: Make this load safe. This file is never closed. Use context manager instead.
f = open(
"eksupdate/src/S3Files/version_dict.json",
"eksupgrade/src/S3Files/version_dict.json",
)
version_dict = json.load(f)

# Kube Proxy config YAML
# kube_proxy_config = s3.Object('eks-one-click-upgrade', 'addons/kube-proxy.json')
# kube_proxy_config = kube_proxy_config.get()['Body'].read().decode('utf-8')
# kube_proxy_config = json.loads(kube_proxy_config)
# TODO: Make this load safe. This file is never closed. Use context manager instead.
f = open(
"eksupdate/src/S3Files/kube-proxy.json",
"eksupgrade/src/S3Files/kube-proxy.json",
)
kube_proxy_config = json.load(f)
kube_proxy_container = kube_proxy_config["spec"]["template"]["spec"]["containers"][0]
Expand All @@ -490,8 +493,9 @@ def addon_version(log_details, errors, cluster_name, region, cluster_details, re
# core_dns_config = s3.Object('eks-one-click-upgrade', 'addons/coredns.json')
# core_dns_config = core_dns_config.get()['Body'].read().decode('utf-8')
# core_dns_config = json.loads(core_dns_config)
# TODO: Make this load safe. This file is never closed. Use context manager instead.
f = open(
"eksupdate/src/S3Files/coredns.json",
"eksupgrade/src/S3Files/coredns.json",
)
core_dns_config = json.load(f)
coredns_container = core_dns_config["spec"]["template"]["spec"]["containers"][0]
Expand All @@ -506,8 +510,9 @@ def addon_version(log_details, errors, cluster_name, region, cluster_details, re
# vpc_cni_config = s3.Object('eks-one-click-upgrade', 'addons/vpc-cni.json')
# vpc_cni_config = vpc_cni_config.get()['Body'].read().decode('utf-8')
# vpc_cni_config = json.loads(vpc_cni_config)
# TODO: Make this load safe. This file is never closed. Use context manager instead.
f = open(
"eksupdate/src/S3Files/vpc-cni.json",
"eksupgrade/src/S3Files/vpc-cni.json",
)
vpc_cni_config = json.load(f)
vpc_cni_container = vpc_cni_config["spec"]["template"]["spec"]["containers"][0]
Expand All @@ -522,8 +527,9 @@ def addon_version(log_details, errors, cluster_name, region, cluster_details, re
# kube_proxy_config_map = s3.Object('eks-one-click-upgrade', 'configMap/kube-proxy.json')
# kube_proxy_config_map = kube_proxy_config_map.get()['Body'].read().decode('utf-8')
# kube_proxy_config_map = json.loads(kube_proxy_config_map)
# TODO: Make this load safe. This file is never closed. Use context manager instead.
f = open(
"eksupdate/src/S3Files/kube-proxy-configmap.json",
"eksupgrade/src/S3Files/kube-proxy-configmap.json",
)
kube_proxy_config_map = json.load(f)
config_map["certificate-authority"] = yaml.safe_load(kube_proxy_config_map["data"]["kubeconfig"])["clusters"][0][
Expand Down Expand Up @@ -1095,8 +1101,9 @@ def depricated_api_check(log_details, errors, cluster_name, region, report, cust
# depricated_api = s3.Object('eks-one-click-upgrade', 'depricatedApi')
# depricated_api = depricated_api.get()['Body'].read().decode('utf-8')
# depricated_api = json.loads(depricated_api)
# TODO: Make this load safe. This file is never closed. Use context manager instead.
f = open(
"eksupdate/src/S3Files/depricatedApi",
"eksupgrade/src/S3Files/depricatedApi",
)
depricated_api = json.load(f)
# print(depricated_api)
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d6b3f41

Please sign in to comment.