在 Kubernetes 上卸载 Instana 代理

您可以根据代理的部署方式,通过多种方法在 Kubernetes 上卸载 Instana 代理。

准备工作

在卸载 Instana 代理之前,您需要先卸载安装在应用程序运行时环境中的追踪器(或进程内收集器)。

如果您的 Kubernetes 环境中包含 PHP 运行时,且在代理配置中已启用 PHP 跟踪(默认启用), configuration.yamlspec.agent.configuration_yaml 则需要按照 “禁用 PHP 跟踪 ”中所述的步骤卸载 PHP Tracer。

卸载跟踪器后,您可以使用以下方法从 Kubernetes 部署中卸载 Instana 代理:

卸载通过操作员安装的代理

若要卸载通过操作员安装的 Instana 代理或远程代理,请按照以下步骤操作:

  1. 通过删除自定义资源文件 YAML 来卸载代理(例如, instana-agent.customresource.yaml 对于 Instana 代理, instana-agent-remote.yaml 请删除 Instana 远程代理):

    kubectl delete -f <custom-resource-file>.yaml
     
  2. 运行以下命令卸载操作符:

    kubectl delete -f https://github.com/instana/instana-agent-operator/releases/latest/download/instana-agent-operator.yaml
     

卸载通过“ Helm ”图表安装的代理

注意: 在运行该 helm uninstall 命令之前,请务必删除您的代理自定义资源(CR)。 否则,该 CR 不会从您的集群中删除。

要卸载通过 Helm 图表安装的 Instana 代理,请运行以下命令:

NAMESPACE=instana-agent
# delete agent custom resource, the operator will remove the agent artifacts it is owning
kubectl delete agents.instana.io instana-agent -n ${NAMESPACE} --wait
# uninstall helm chart which removes the operator and RBAC artifacts
helm uninstall instana-agent -n ${NAMESPACE}
# manually uninstall the custom resource definition which is not uninstalled by helm
kubectl delete crd agents.instana.io
# remove the entire namespace
kubectl delete namespace ${NAMESPACE}
 

Instana Helm 的第 2 版或更高版本会在后台安装 instana-operator。 在卸载过程中, Helm 不会自动删除自定义资源定义或自定义资源。 因此,仅执行该 helm uninstall 命令是不够的。

Instana 在版本 2.0.0 之前, Helm 图表安装不会安装代理自定义资源和自定义资源定义。 在进行这些安装时,您可能会收到有关无法找到资源的通知。 这是预期的行为。

如果您在删除 CR 之前先运行了该 helm uninstall 命令,请使用以下命令从集群中移除整个代理安装:

NAMESPACE=instana-agent
# remove the finalizer
kubectl patch agents.instana.io instana-agent -p '{"metadata":{"finalizers":null}}' --type=merge -n ${NAMESPACE}
# remove the cluster-wide objects
kubectl delete crd/agents.instana.io clusterrole/leader-election-role clusterrole/instana-agent-clusterrole clusterrolebinding/leader-election-rolebinding clusterrolebinding/instana-agent-clusterrolebinding
# remove helm chart,if still present
helm uninstall instana-agent -n ${NAMESPACE} || true
# delete the entire namespace
kubectl delete ns ${NAMESPACE} --wait || true
 

要卸载 Instana AutoTrace WebHook, ,请参阅 《卸载 Instana 》 AutoTrace WebHook