# Clean-up

Clean-up

Configure kubeconfig:

export MY_DOMAIN="mylabs.dev"
kops export kubecfg ${USER}-k8s.${MY_DOMAIN} --state=s3://${USER}-kops-k8s --kubeconfig /tmp/kubeconfig.conf
export KUBECONFIG=/tmp/kubeconfig.conf

Remove DNS records:

kubectl delete gateways.networking.istio.io --all --all-namespaces && \
kubectl delete pod -n external-dns --all && \
sleep 15

Output:

gateway.networking.istio.io "el-getting-started-listener-gateway" deleted
gateway.networking.istio.io "gitlab-gateway" deleted
gateway.networking.istio.io "harbor-gateway" deleted
gateway.networking.istio.io "istio-autogenerated-k8s-ingress" deleted
gateway.networking.istio.io "istio-services-gateway" deleted
gateway.networking.istio.io "knative-services-gateway" deleted
gateway.networking.istio.io "cluster-local-gateway" deleted
gateway.networking.istio.io "knative-ingress-gateway" deleted
pod "external-dns-685b847795-mrchv" deleted

Delete GitHub repositories:

hub delete -y ruzickap/podinfo

Cleanup + Remove Helm:

test -d /home/${USER}/.helm        && rm -rf /home/${USER}/.helm
test -d /home/${USER}/.config/helm && rm -rf /home/${USER}/.config/helm

Cleanup + Remove tmp directory:

rm -rf tmp

Docker certificate cleanup if exists:

sudo rm -rf /etc/docker/certs.d/harbor.${MY_DOMAIN}

Remove K8s cluster:

kops delete cluster --name=${USER}-k8s.${MY_DOMAIN} --yes --state=s3://${USER}-kops-k8s

Output:

...
Deleted kubectl config for pruzicka-k8s.mylabs.de

Remove S3 bucket used for storing the configuration by kops:

aws s3 rm s3://${USER}-kops-k8s/${USER}-app-build.tar
aws s3api delete-bucket --bucket ${USER}-kops-k8s --region eu-central-1

Clean Policy, User, Access Key in AWS:

# aws route53 delete-hosted-zone --id $(aws route53 list-hosted-zones --query "HostedZones[?Name==\`${MY_DOMAIN}.\`].Id" --output text)

POLICY_ARN=$(aws iam list-policies --query "Policies[?PolicyName==\`${USER}-k8s-${MY_DOMAIN}\`].{ARN:Arn}" --output text) && \
aws iam detach-user-policy --user-name "${USER}-k8s-${MY_DOMAIN}" --policy-arn ${POLICY_ARN} && \
aws iam delete-policy --policy-arn ${POLICY_ARN}

USER_ACCESS_KEYS=$(aws iam list-access-keys --user-name ${USER}-k8s-${MY_DOMAIN} --query "AccessKeyMetadata[].AccessKeyId" --output text) && \
aws iam delete-access-key --user-name ${USER}-k8s-${MY_DOMAIN} --access-key-id ${USER_ACCESS_KEYS}

aws iam delete-user --user-name ${USER}-k8s-${MY_DOMAIN}

Remove other files:

rm demo-magic.sh kubeconfig.conf README.sh &> /dev/null