We use machine learning technology to do auto-translation. Click "English" on top navigation bar to check Chinese version.
Monitoring version compliance of Amazon Elastic Kubernetes Service by using Amazon Web Services Config
A Kubernetes cluster has a control plane and a data plane. The Kubernetes software running in the different planes need updates to remain up-to-date. The control plane updates are managed by Amazon Web Services, so you only have to launch the process for new minor version. For the data plane, Amazon EKS makes the upgrade for the infrastructure layer a straightforward process by providing
Using Amazon Web Services Config to monitor Amazon EKS
In this post, we will use
Amazon Web Services Config publishes the event to
Here’s the architecture diagram of the Amazon Web Services Config rule that we will deploy:
The different components in this solution are :
- An Amazon Web Services Config managed rule that checks the EKS Control plane version.
- An Amazon Web Services Config Custom Lambda Rule that monitors new AMI version for our Managed Node Group.
- All events generated by Amazon Web Services Config are sent to Amazon EventBridge. Through event pattern, you can trigger notifications to stakeholders (email, http, etc.) or forward them to other targets.
Prerequisites:
You will need the following to complete the steps for the Amazon Web Services managed rule section:
- Amazon Web Services Config enabled in your account, if required you can use the
1-click setup directly from the console.
For the Amazon Web Services Config Custom Lambda Rule section, you will need to:
- Install the
Amazon Web Services Command Line Interface (Amazon Web Services CLI) . - Install the
Amazon Web Services Serverless Application Model Command Line (Amazon Web Services SAM CLI). - Install
Git . - Install
Node.js and npm .
Monitor EKS control plane version through Amazon Web Services Config managed rules
For Amazon EKS, we can ensure that the version of our control plane is within a supported version by using the
To enable the eks-cluster-supported-version from Amazon Web Services Config:
- Open the Amazon Web Services Config console.
- In the navigation pane, choose Rules.
- Choose Add rule.
- Under Amazon Web Services Managed Rules , search for EKS.
- Select eks-cluster-supported-version , choose Next.
- Under Parameter , in the Value column, input the latest version of EKS you want to consider compliant. At the time of this writing, I’m using 1.26.
- Choose Next , review your rule and click Add rule.
- Select the new rule from the list and under Actions , choose Re-evaluate .
This screenshot shows the rule details with three clusters in your account.
Extending Amazon Web Services Config to monitor EKS Managed Node Groups (MNG) by leveraging Amazon Web Services Lambda
The following steps create an Amazon Web Services Config Custom Lambda Rule and enable it for our managed node groups using the code from our
Installation procedure:
Let’s start by creating the required Lambda using sam-cli tool:
# You can download the zip from github instead of git clone
git clone https://github.com/aws-samples/aws-config-eks-mng-checkupdate.git
cd aws-config-eks-mng-checkupdate
sam build
sam deploy --guided
We suggest config-custom-rule-eks-mng
as the value for the Stack Name . Use default for the other options.
Here’s the sample output of this command:
Deploying with following values
===============================
Stack name : config-custom-rule-eks-mng
Region : ca-central-1
Confirm changeset : True
Disable rollback : False
Deployment s3 bucket : aws-sam-cli-managed-default-samclisourcebucket-xxxxx
Capabilities : ["CAPABILITY_IAM"]
Parameter overrides : {}
Signing Profiles : {}
…
Successfully created/updated stack - config-eks-ami in ca-central-1
This will create a Lambda as well as the custom rule EKS-MNG-CheckUpdate
in Amazon Web Services Config with the resource policy to invoke that Lambda. The IAM role created for Lambda has read-only permission on EKS as well as GetParameter
from
Periodic trigger type
Amazon Web Services Config rules can be triggered on a periodic schedule or a configuration change. Amazon Web Services Config currently does not provide support for managed node group (MNG). In order to evaluate a MNG resource, we defined an Amazon Web Services Config Custom Lambda Rule that runs periodically. There are multiple periodic choices, from every hour to every 24 hours. Considering this is linked to AMI update frequencies, we chose the 24 hours period through our template. Note that your Amazon Web Services Config costs will increase with more rule evaluations. To learn more, see Amazon Web Services Config
Here’s a view of results provided by the custom rule from the Amazon Web Services Config console:
The current version of the Amazon Web Services Config rule support node running the
Event pattern to filter events in Amazon EventBridge
If you want to react to any compliance changes happening with our new rules inside EventBridge. Here’s an example of an event pattern that cover rules used today:
{
"source": ["aws.config"],
"detail-type": ["Config Rules Compliance Change"],
"detail": {
"configRuleName": ["EKS-MNG-CheckUpdate", "eks-cluster-supported-version"]
}
}
For the targets, it’s possible to select from a wide-range of Amazon Web Services Services and even external API, see the
Cleanup
To prevent additional charges to your account, the following steps will delete the resources that were created:
1 – Through the Amazon Web Services Config console. Select the rule eks-cluster-supported-version
and from the action menu, use the Delete rule option.
2 – Delete the custom rule and associated resources via the following command:
sam delete --stack-name config-custom-rule-eks-mng
3 – In the EventBridge console, delete the rule that was added (if any).
Conclusion
In this blog post, we have demonstrated how you can track your EKS Version both at the control and data plane level. By leveraging Amazon Web Services Config rules (managed and custom), you can automate the effort needed to track effective version.
To get a centralized view of your clusters and managed node group version, you can set up an
The mentioned AWS GenAI Services service names relating to generative AI are only available or previewed in the Global Regions. Amazon Web Services China promotes AWS GenAI Services relating to generative AI solely for China-to-global business purposes and/or advanced technology introduction.