简体   繁体   中英

how to move prometheus adapter to another namespace?

For now I have prometheus and prometheus adapter in different namespaces:文本

I tried to configure adapter YML but I was not successful: apiVersion: apps/v1 kind: Deployment metadata:

  annotations:
    deployment.kubernetes.io/revision: "2"
  creationTimestamp: "2020-01-30T08:49:05Z"
  generation: 2
  labels:
    app: prometheus-adapter
    chart: prometheus-adapter-2.0.1
    heritage: Tiller
    release: prometheus-adapter
  name: prometheus-adapter
  namespace: my-custom-namespace
  resourceVersion: "18513075"
  selfLink: /apis/apps/v1/namespaces/my-custom-namespace/deployments/prometheus-adapter
  ...

But I see error:

the namespace of the object (my-custom-namespace) does not match the namespace on the request (default)

How to fix it ?

You can not edit an existing resource to change namespace.You need to delete the existing deployment first and then recreate the deployment in another namespace.

Edit:

With Helm2 you need to delete the release first helm delete --purge release-name and then deploy it to different namespace as helm install stable/prometheus-adapter --namespace namespace-name

With helm 3 since there is no --namespace flag you need to delete the existing deployment and then redeploy it to a different namespace as below example to deploy metrics server.

$ helm install metricserver stable/metrics-server
Error: the namespace from the provided object "kube-system" does not          match the namespace "default". You must pass '--namespace=kube-system' to perform this operation.

$ helm install metricserver stable/metrics-server --namespace=kube-system
Error: the namespace from the provided object "kube-system" does not match the namespace "default". You must pass '--namespace=kube-system' to perform this operation.

$ kubectl config set-context kube-system --cluster=kubernetes --user=kubernetes-admin --namespace=kube-system
Context "kube-system" created.

$ kubectl config use-context kube-system
Switched to context "kube-system".

$ kubectl config get-contexts
CURRENT   NAME                          CLUSTER      AUTHINFO           NAMESPACE
*         kube-system                   kubernetes   kubernetes-admin   kube-system
          kubernetes-admin@kubernetes   kubernetes   kubernetes-admin
          metallb                       kubernetes   kubernetes-admin   metallb
          nfstorage                     kubernetes   kubernetes-admin   nfstorage

$ helm install metricserver stable/metrics-server
NAME: metricserver
LAST DEPLOYED: 2019-05-26 14:37:45.582245559 -0700 PDT m=+2.942929639
NAMESPACE: kube-system
STATUS: deployed

For helm 2 you can install the chart in any namespace you want by using:

helm install stable/prometheus-adapter --name my-release --namespace foo

Keep in mind that you need to remove the previous one.

This can be done using helm delete --purge my-release

Also there is a really nice article regarding changes in Helm3 Breaking Changes in Helm 3 (and How to Fix Them) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM