-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using terraform to apply cluster AWS resources changes, you must update the ASGs to use launch templates #10017
Comments
similar issue faced when we updating cluster to k8s
|
So we discussed this a bit and came up with two ideas, perhaps you and others could provide input on them? The problem is that Kops' migration from LaunchConfigurations to LaunchTemplates causes the generated terraform file to no longer include the LC. Terraform then tries to delete the LC even though it is still in use by the autoscaling groups until their instances have all be replaced with the new LT version.
|
@rifelpet I'm going to try out your second suggestion today. Whatever script I come up with to remove all of the LC resources prior to running |
@rifelpet thanks for you suggestions. I tried the following terraform updates, and it allowed to terraform apply to go through without any deletion errors.
I'll post the command I'll use with the aws cli to remove the old LCs. |
@rifelpet 1st option is more transparent for users. 👍 |
Per @rifelpet's ideas above (in #10017 (comment)), when I ran into this problem, I used that second procedure: delete the Launch Configurations from Terraform's state using terraform state rm, orphaning them. Terraform was not smart enough to first create the Launch Templates, bind the templates to the ASG, and only then destroy the abandoned Launch Configurations. It always wanted to destroy the Launch Configurations first, before adjusting the ASGs that had been using them. |
I ran into the same issue regarding using LTs with mixed instance policies as @avdhoot, though I think it's a different issue from the one at hand here. This was with a cluster created and then updated with |
Here's my latest code handling this problem as part of a larger upgrade procedure. # kops removes the Terraform configuration for the existing
# autoscaling launch configurations, so Terraform tries to delete
# them, only too early, before it reconfigures the ASGs using them to
# use launch templates instead. Preclude Terraform from making that
# mistake by removing the launch configuration resources from its
# state file, and then deleting these orphaned launch configurations
# after Terraform is done with the ASGs.
launch_configurations_to_delete=()
while read -r tf_address lc_name; do
# Even when there's no output from jq, the "read" command still
# enters the loop once with an empty line.
if [ -z "${lc_name}" ]; then
break
fi
launch_configurations_to_delete+=("${lc_name}")
terraform state rm "${tf_address}"
done <<< \
"$(terraform show -json |
jq --raw-output '.values.root_module.resources[]
| select(.type == "aws_launch_configuration")
| [.address, .values.name]
| @tsv')" \
|| : # NB: The "read" command fails upon reaching EOF.
terraform apply -auto-approve
for lc_name in "${launch_configurations_to_delete[@]}"; do
AWS_PAGER='' aws autoscaling delete-launch-configuration --launch-configuration-name "${lc_name}"
done
rm data/aws_launch_configuration*user_data |
Would you mind testing again with the 1.19.0-beta.2 release? |
@hakman still same issue with Update: Please ignore above comment. I was confused with other issue. |
@avdhoot what terraform version are you using? |
1. What
kops
version are you running? The commandkops version
, will displaythis information.
kops 1.19-alpha-4
2. What Kubernetes version are you running?
kubectl version
will print theversion if a cluster is running or provide the Kubernetes version specified as
a
kops
flag.k8s 1.19.2
3. What cloud provider are you using?
aws
4. What commands did you run? What is the simplest way to reproduce this issue?
applied new terraform created from kops update-cluster --target=terraform, using terraform apply
5. What happened after the commands executed?
The existing launch configurations are still attached to the ASGs, so the deletion of them will fail. You have to update the ASGs to use the launch templates through the UI or aws CLI, then run terraform apply again.
6. What did you expect to happen?
terraform would not fail on applying the new cluster terraform file
7. Please provide your cluster manifest. Execute
kops get --name my.example.com -o yaml
to display your cluster manifest.You may want to remove your cluster name and other sensitive information.
8. Please run the commands with most verbose logging by adding the
-v 10
flag.Paste the logs into this report, or in a gist and provide the gist link here.
9. Anything else do we need to know?
This is really informational only, not a bug, but I'd like this known so others that use terraform know that they have to handle the switch from launch configurations to launch templates outside of terraform and kops, since terraform will fail deleting the old launch configurations b/c they are still assigned to ASGs.
The text was updated successfully, but these errors were encountered: