Last active
February 10, 2023 12:23
-
-
Save andrewbulin/e23c313008372d4e5149899817bebe32 to your computer and use it in GitHub Desktop.
upgrade EKS 1.21 to 1.22 with KubectlLayer upgrade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// main created and tweaked from original output of `cdk init app --language go` | |
package main | |
import ( | |
"github.com/aws/aws-cdk-go/awscdk/v2" | |
"github.com/aws/aws-cdk-go/awscdk/v2/awseks" | |
"github.com/aws/constructs-go/constructs/v10" | |
"github.com/aws/jsii-runtime-go" | |
// for KubectlLayer upgrade, reference: | |
// * https://github.com/aws/aws-cdk/issues/19843#issuecomment-1341715811 | |
// * https://github.com/cdklabs/awscdk-kubectl-go/tree/kubectl.22/kubectlv22 | |
// | |
// go get github.com/cdklabs/awscdk-kubectl-go/kubectlv22/v2 | |
"github.com/cdklabs/awscdk-kubectl-go/kubectlv22/v2" | |
) | |
type GoCdkStackProps struct { | |
awscdk.StackProps | |
} | |
func NewGoCdkStack(scope constructs.Construct, id string, props *GoCdkStackProps) awscdk.Stack { | |
var sprops awscdk.StackProps | |
if props != nil { | |
sprops = props.StackProps | |
} | |
stack := awscdk.NewStack(scope, &id, &sprops) | |
// The code that defines your stack goes here | |
// example resource | |
// queue := awssqs.NewQueue(stack, jsii.String("GoCdkQueue"), &awssqs.QueueProps{ | |
// VisibilityTimeout: awscdk.Duration_Seconds(jsii.Number(300)), | |
// }) | |
//// ZA CLUSTA | |
// | |
cluster := awseks.NewCluster( | |
stack, | |
jsii.String("UpgradeMe"), | |
&awseks.ClusterProps{ | |
Version: awseks.KubernetesVersion_V1_22(), | |
KubectlLayer: kubectlv22.NewKubectlV22Layer(stack, jsii.String("kubectl")), | |
ClusterName: jsii.String("upgrade-me"), | |
ClusterLogging: &[]awseks.ClusterLoggingTypes{ | |
awseks.ClusterLoggingTypes_AUDIT, | |
}, | |
}, | |
) | |
//// PROMETHEUS | |
// | |
cluster.AddHelmChart( | |
jsii.String("KubePrometheusStack"), | |
&awseks.HelmChartOptions{ | |
Chart: jsii.String("kube-prometheus-stack"), | |
Repository: jsii.String("https://prometheus-community.github.io/helm-charts"), | |
CreateNamespace: jsii.Bool(true), | |
Release: jsii.String("prometheus"), | |
}, | |
) | |
//// HELLO-KUBERNETES | |
// | |
appLabel := map[string]*string{ | |
"app": jsii.String("hello-kubernetes"), | |
} | |
deployment := map[string]interface{}{ | |
"apiVersion": jsii.String("apps/v1"), | |
"kind": jsii.String("Deployment"), | |
"metadata": map[string]*string{ | |
"name": jsii.String("hello-kubernetes"), | |
}, | |
"spec": map[string]interface{}{ | |
"replicas": jsii.Number(3), | |
"selector": map[string]map[string]*string{ | |
"matchLabels": appLabel, | |
}, | |
"template": map[string]interface{}{ | |
"metadata": map[string]map[string]*string{ | |
"labels": appLabel, | |
}, | |
"spec": map[string][]map[string]interface{}{ | |
"containers": { | |
map[string]interface{}{ | |
"name": jsii.String("hello"), | |
"image": jsii.String("paulbouwer/hello-kubernetes:1.5"), | |
"ports": []map[string]*float64{ | |
{ | |
"containerPort": jsii.Number(8080), | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
} | |
service := map[string]interface{}{ | |
"apiVersion": jsii.String("v1"), | |
"kind": jsii.String("Service"), | |
"metadata": map[string]*string{ | |
"name": jsii.String("hello-kubernetes"), | |
}, | |
"spec": map[string]interface{}{ | |
"type": jsii.String("LoadBalancer"), | |
"ports": []map[string]*float64{ | |
{ | |
"port": jsii.Number(80), | |
"targetPort": jsii.Number(8080), | |
}, | |
}, | |
"selector": appLabel, | |
}, | |
} | |
cluster.AddManifest(jsii.String("hello-kubernetes"), &service, &deployment) | |
return stack | |
} | |
func main() { | |
defer jsii.Close() | |
app := awscdk.NewApp(nil) | |
NewGoCdkStack(app, "GoCdkStack", &GoCdkStackProps{ | |
awscdk.StackProps{ | |
Env: env(), | |
}, | |
}) | |
app.Synth(nil) | |
} | |
// env determines the AWS environment (account+region) in which our stack is to | |
// be deployed. For more information see: https://docs.aws.amazon.com/cdk/latest/guide/environments.html | |
func env() *awscdk.Environment { | |
// If unspecified, this stack will be "environment-agnostic". | |
// Account/Region-dependent features and context lookups will not work, but a | |
// single synthesized template can be deployed anywhere. | |
//--------------------------------------------------------------------------- | |
return nil | |
// Uncomment if you know exactly what account and region you want to deploy | |
// the stack to. This is the recommendation for production stacks. | |
//--------------------------------------------------------------------------- | |
// return &awscdk.Environment{ | |
// Account: jsii.String("123456789012"), | |
// Region: jsii.String("us-east-1"), | |
// } | |
// Uncomment to specialize this stack for the AWS Account and Region that are | |
// implied by the current CLI configuration. This is recommended for dev | |
// stacks. | |
//--------------------------------------------------------------------------- | |
// return &awscdk.Environment{ | |
// Account: jsii.String(os.Getenv("CDK_DEFAULT_ACCOUNT")), | |
// Region: jsii.String(os.Getenv("CDK_DEFAULT_REGION")), | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
kubectl results:
NOTE: The nodes themselves will need to be upgraded separately. (something I'm willing to do via eksctl or console at this time)