# easiest way, use the defaults# creates role, VPC, EC2 ASG
rm -rf /tmp/${USER}-test-ec2*
ec2-utils create instances --enable-prompt=true -p /tmp/${USER}-test-ec2.yaml
ec2-utils delete instances --enable-prompt=true -p /tmp/${USER}-test-ec2.yaml
# advanced options can be set via environmental variables
rm -rf /tmp/${USER}-test-ec2*
AWS_K8S_TESTER_EC2_ON_FAILURE_DELETE=true \
AWS_K8S_TESTER_EC2_PARTITION=aws \
AWS_K8S_TESTER_EC2_REGION=us-west-2 \
AWS_K8S_TESTER_EC2_S3_BUCKET_CREATE=true \
AWS_K8S_TESTER_EC2_S3_BUCKET_CREATE_KEEP=true \
AWS_K8S_TESTER_EC2_REMOTE_ACCESS_KEY_CREATE=true \
AWS_K8S_TESTER_EC2_ASGS_FETCH_LOGS=true \
AWS_K8S_TESTER_EC2_ASGS='{"GetRef.Name-al2-cpu":{"name":"GetRef.Name-al2-cpu","remote-access-user-name":"ec2-user","ami-type":"AL2_x86_64","image-id-ssm-parameter":"/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2","instance-types":["c5.xlarge"],"volume-size":40,"asg-min-size":1,"asg-max-size":1,"asg-desired-capacity":1},"GetRef.Name-bottlerocket":{"name":"GetRef.Name-bottlerocket","remote-access-user-name":"ec2-user","ami-type":"BOTTLEROCKET_x86_64","image-id-ssm-parameter":"/aws/service/bottlerocket/aws-k8s-1.15/x86_64/latest/image_id","ssm-document-cfn-stack-name":"GetRef.Name-install-bottlerocket","ssm-document-name":"GetRef.Name-install-bottlerocket","ssm-document-create":true,"ssm-document-commands":"enable-admin-container","ssm-document-execution-timeout-seconds":3600,"instance-types":["c5.xlarge"],"volume-size":40,"asg-min-size":1,"asg-max-size":1,"asg-desired-capacity":1}}' \
AWS_K8S_TESTER_EC2_ROLE_CREATE=true \
AWS_K8S_TESTER_EC2_VPC_CREATE=true \
ec2-utils create instances --enable-prompt=true -p /tmp/${USER}-test-ec2.yaml
<<COMMENT# to deleteec2-utils delete instances --enable-prompt=true -p /tmp/${USER}-test-ec2.yaml# run "ec2 create config" to check/edit configuration file first ec2-utils create config -p /tmp/${USER}-test-ec2.yamlec2-utils create instances -p /tmp/${USER}-test-ec2.yaml# run the following command with those envs overwrites configuration, and createec2-utils create instances --enable-prompt=true -p /tmp/${USER}-test-ec2.yamlCOMMENT<<COMMENT# to config a fixed name for EC2 ASGAWS_K8S_TESTER_EC2_NAME=${NAME}\# to create/delete a S3 bucket for test artifactsAWS_K8S_TESTER_EC2_S3_BUCKET_CREATE=true \# to reuse an existing S3 bucketAWS_K8S_TESTER_EC2_S3_BUCKET_CREATE=false \AWS_K8S_TESTER_EC2_S3_BUCKET_NAME=${BUCKET_NAME}\# to automatically create EC2 key-pairAWS_K8S_TESTER_EC2_REMOTE_ACCESS_KEY_CREATE=true \# to reuse an existing EC2 key-pairAWS_K8S_TESTER_EC2_REMOTE_ACCESS_KEY_CREATE=false \AWS_K8S_TESTER_EC2_REMOTE_ACCESS_KEY_NAME=${KEY_NAME}\AWS_K8S_TESTER_EC2_REMOTE_ACCESS_PRIVATE_KEY_PATH=${KEY_PATH}\# to reuse an existing roleAWS_K8S_TESTER_EC2_ROLE_CREATE=false \AWS_K8S_TESTER_EC2_ROLE_ARN=${ROLE_ARN}\# to reuse an existing VPCAWS_K8S_TESTER_EC2_VPC_CREATE=false \AWS_K8S_TESTER_EC2_VPC_ID=${VPC_ID}\# to use ${USER}AWS_K8S_TESTER_EC2_ASGS={\"${USER}-test-ec2-al2-cpu\":{\"name\":\"${USER}-test-ec2-al2-cpu\",\"remote-access-user-name\":\"ec2-user\",\"ami-type\":\"AL2_x86_64\",\"image-id-ssm-parameter\":\"/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2\",,\"instance-types\":[\"c5.xlarge\"],\"volume-size\":40,\"asg-min-size\":1,\"asg-max-size\":1,\"asg-desired-capacity\":1},\"${USER}-test-ec2-bottlerocket\":{\"name\":\"${USER}-test-ec2-bottlerocket\",\"remote-access-user-name\":\"ec2-user\",\"ami-type\":\"BOTTLEROCKET_x86_64\",\"image-id-ssm-parameter\":\"/aws/service/bottlerocket/aws-k8s-1.15/x86_64/latest/image_id\",\"ssm-document-cfn-stack-name\":\"${USER}-install-bottlerocket\",\"ssm-document-name\":\"${USER}InstallBottleRocket\",\"ssm-document-create\":true,\"ssm-document-commands\":\"enable-admin-container\",\"ssm-document-execution-timeout-seconds\":3600,,\"instance-types\":[\"c5.xlarge\"],\"volume-size\":40,\"asg-min-size\":1,\"asg-max-size\":1,\"asg-desired-capacity\":1}} \COMMENT
WARNING: kubectl internally converts API versions in the response (see kubernetes/issues#58131). Which means kubectl get output may have different API versions than the one persisted in etcd. Upstream Kubernetes recommends upgrading deprecated API with get and put:
the simplest approach is to get/put every object after upgrades. objects that don't need migration will no-op (they won't even increment resourceVersion in etcd). objects that do need migration will persist in the new preferred storage version
Which means there's no way in client-side to find all resources created with deprecated API groups. The only way to ensure API group upgrades is list all resources, and execute get and put with the latest API group version. If the resource has already latest API version, it will be no-op. Otherwise, it will upgrade to the latest API version.
eks-utils apis will help with the list calls with proper pagination and generate get and put scripts for the cluster:
# to check supported API groups from current kube-apiserver
eks-utils apis \
--kubeconfig /tmp/kubeconfig.yaml \
supported
# to write API upgrade/rollback scripts and YAML files in "/tmp/eks-utils"## make sure to set proper "--batch-limit" and "--batch-interval"# to not overload EKS master; if it's set too high, it can affect# production workloads slowing down kube-apiserver
rm -rf /tmp/eks-utils-resources
eks-utils apis \
--kubeconfig /tmp/kubeconfig.yaml \
--enable-prompt \
deprecate \
--batch-limit 10 \
--batch-interval 2s \
--dir /tmp/eks-utils-resources
# this command does not apply or create any resources# it only lists the resources that need be upgraded# if there's any resources that needs upgrade,# it writes patched YAML file, original YAML file,# bash scripts to update and rollback
find /tmp/eks-utils-resources
WARNING: kubectl internally converts API versions in the response (see kubernetes/issues#58131). Which means kubectl get output may have different API versions than the one persisted in etcd . Upstream Kubernetes recommends upgrading deprecated API with get and put:
the simplest approach is to get/put every object after upgrades. objects that don't need migration will no-op (they won't even increment resourceVersion in etcd). objects that do need migration will persist in the new preferred storage version
To minimize the impact of list calls, etcd-utils k8s list reads keys with leadership election and pagination; only a single worker can run at a time.
# to list all deployments with etcd pagination + k8s decoder
etcd-utils k8s \
--endpoints http://localhost:2379 \
list \
--prefixes /registry/deployments \
--output /tmp/etcd-utils-k8s-list.output.yaml
# or ".json"
请发表评论