Skip to content

Transform Kubernetes Manifests using Amazon Q Developer

4 minute read
Content level: Foundational
0

Converting Kubernetes Pod manifests to other Kubernetes resource such as StatefulSet becomes essential when your applications require stability and persistent storage. Amazon Q Developer simplifies this transformation process, helping you create production-ready configurations for workloads in Amazon EKS.

Introduction

Transforming Kubernetes manifests is a common yet crucial task for cluster operators who need to adapt and evolve their containerized applications. Whether converting simple Pod definitions to more robust Deployments or StatefulSets, or modifying DaemonSets for cluster-wide operations, these transformations require careful consideration of application requirements, resource management, and operational best practices. While traditionally this process involved manual editing and potential for errors, Amazon Q Developer offer intelligent assistance in converting and validating these manifests, ensuring proper implementation of Kubernetes-specific features such as pod affinity rules, resource quotas, and security contexts. This streamlined approach not only saves valuable time but also helps maintain consistency and reliability across different Kubernetes resources, ultimately leading to more robust and maintainable cluster configurations.

In a real-world use case, converting Kubernetes Pod manifests to StatefulSet is a common approach when your applications require high availability and persistent storage. Amazon Q Developer simplifies this task, helping you create production-ready StatefulSet configurations. This post demonstrates how Amazon Q Developer can accelerate this conversion process.

Prerequisites

Before proceeding, ensure:

Walkthrough

  1. Initial Pod Manifest
  • Let's start with a basic Llama2 (fine-tuned large language model) Pod manifest that we'll convert:
apiVersion: v1
kind: Pod
metadata:
  labels:
    role: head
  name: llama2
  namespace: aiml
spec:
  nodeSelector:
    instanceType: "neuron"
  volumes:
    - name: ray-logs
      emptyDir: {}    
  containers:
    - name: llama2
      image: public.ecr.aws/data-on-eks/ray2.22.0-py310-llama2-13b-neuron:latest
      lifecycle:
        preStop:
          exec:
            command: ["/bin/sh", "-c", "ray stop"]      
      ports:
        - containerPort: 6379
          name: gcs
        - containerPort: 8265
          name: dashboard
        - containerPort: 10001
          name: client
        - containerPort: 8000
          name: serve
      volumeMounts:
        - mountPath: /tmp/ray
          name: ray-logs
      resources:
        limits:
          cpu: 1
          memory: 2Gi
        requests:
          cpu: 1
          memory: 2Gi
      env:
        - name: LD_LIBRARY_PATH
          value: "/home/ray/anaconda3/lib:$LD_LIBRARY_PATH"  
  1. Using Amazon Q Developer for Kubernetes Conversion
  • Open Amazon Q Developer in the AWS Console or Choose the Amazon Q icon in your VS Code
  • Start a new conversation
  • Paste your Pod manifest or reference the manifest file name and request conversion to a StatefulSet manifest
  • Review the generated StatefulSet manifest:
  • StatefulSet manifest generated by Amazon Q Developer
  1. Customizing the StatefulSet Additionally, Amazon Q Developer can help customize the StatefulSet with:
  • Adjusting replica count
  • Configuring update strategies
  • Setting pod management policies
  • Adding initialization containers
  • Implementing health checks
  1. Deploying to Amazon EKS Save the output as sts.yml and apply the generated StatefulSet manifest:
% kubectl apply -f sts.yml       
statefulset.apps/llama2 created
service/llama2 created

% kubectl get po -n aiml
NAME       READY   STATUS    RESTARTS   AGE
llama2-0   1/1     Running   0          2m59s

Note: Amazon Q Developer can suggest StatefulSet best practices for example:

  • Implementing proper backup strategies
  • Configuring volume retention policies
  • Setting up pod disruption budgets
  • Configuring readiness gates
  • Managing rolling updates

Cleaning Up

To avoid ongoing charges, clean up the resources:

kubectl delete -f sts.yml   

Conclusion

Amazon Q Developer can streamline the process of converting Kubernetes manifests to your desired configurations, helping you with accelerated transformations in your Kubernetes environment. Using Amazon Q Developer can improve how you operate your Amazon EKS clusters.