Skip to content

Helm 3 doesn't create namespace #5753

Closed

Description

@kevtaylor

Output of helm version:

version.BuildInfo{Version:"v3.0.0-alpha.1", GitCommit:"b9a54967f838723fe241172a6b94d18caf8bcdca", GitTreeState:"clean"}

Output of kubectl version:

Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.3", GitCommit:"721bfa751924da8d1680787490c54b9179b1fed0", GitTreeState:"clean", BuildDate:"2019-02-01T20:08:12Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"11+", GitVersion:"v1.11.8-eks-7c34c0", GitCommit:"7c34c0d2f2d0f11f397d55a46945193a0e22d8f3", GitTreeState:"clean", BuildDate:"2019-03-01T22:49:39Z", GoVersion:"go1.10.8", Compiler:"gc", Platform:"linux/amd64"}

Cloud Provider/Platform (AKS, GKE, Minikube etc.):
AWS/EKS

centos7:[root@localhost linux-amd64]$ kubectl get ns nginx
Error from server (NotFound): namespaces "nginx" not found
centos7:[root@localhost linux-amd64]$ ./helm install nginx stable/nginx-ingress
Error: create: failed to create: namespaces "nginx" not found
centos7:[root@localhost linux-amd64]$ kubectl create ns nginx
namespace/nginx created
centos7:[root@localhost linux-amd64]$ ./helm install nginx stable/nginx-ingress
NAME: nginx
LAST DEPLOYED: 2019-05-17 15:30:04.283642019 +0100 BST m=+4.727707147
NAMESPACE: nginx
STATUS: deployed

NOTES:
The nginx-ingress controller has been installed.
It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status by running 'kubectl --namespace nginx get services -o wide -w nginx-nginx-ingress-controller'

An example Ingress that makes use of the controller:

  apiVersion: extensions/v1beta1
  kind: Ingress
  metadata:
    annotations:
      kubernetes.io/ingress.class: nginx
    name: example
    namespace: foo
  spec:
    rules:
      - host: www.example.com
        http:
          paths:
            - backend:
                serviceName: exampleService
                servicePort: 80
              path: /
    # This section is only required if TLS is to be enabled for the Ingress
    tls:
        - hosts:
            - www.example.com
          secretName: example-tls

If TLS is enabled for the Ingress, a Secret containing the certificate and key must also be provided:

  apiVersion: v1
  kind: Secret
  metadata:
    name: example-tls
    namespace: foo
  data:
    tls.crt: <base64 encoded cert>
    tls.key: <base64 encoded key>
  type: kubernetes.io/tls

Activity

  1. added
    bug
    v3.x
    on May 17, 2019
  2. rpeets commented on May 26, 2019

    @rpeets

    run in to the same issue.. but resolved by switching context as mentioned in #5628
    at this point i believe its just confusing to have --namespace an option.

  3. jeremy-donson commented on May 27, 2019

    @jeremy-donson

    @rpeets - To clarify my understanding of your last comment:
    Proper and consistent usage of namespaces across environments is definitely a k8s best practice, no?

    #5628

    I believe the environment and namespace are crucial means to properly "target" deployments.
    And helm seems to be in the cockpit of that

    @bacongobbler => Feel free to set me straight here. Thx in advance.
    I just went full circle from #5628 and back. :)

    These Helm 3.x issues + helm3 hooks are crucial aspects of our emerging workflows,
    and we are interested in where this will go.

  4. rpeets commented on May 27, 2019

    @rpeets

    @jeremy-donson - I 100% agree with you thats the best practice.
    but the error message is confusing, as you can see blow.
    Since its not suppose to work, these message is pointing you the wrong direction.
    "You must pass '--namespace=kube-system' to perform this operation."

    $ 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
    
    NOTES:
    The metric server has been deployed.
    
  5. hickeyma commented on May 27, 2019

    @hickeyma
    Contributor

    I can verify this bug from the v3 master code, and using the scaffold chart as follows:

    $ helm install chrt-5753 chrt-5753/ 
    NAME: chrt-5753
    LAST DEPLOYED: 2019-05-27 16:29:33.256126018 +0100 IST m=+0.094848038
    NAMESPACE: default
    STATUS: deployed
    
    NOTES:
    1. Get the application URL by running these commands:
      export POD_NAME=$(kubectl get pods -l "app=chrt-5753,release=chrt-5753" -o jsonpath="{.items[0].metadata.name}")
      echo "Visit http://127.0.0.1:8080 to use your application"
    
    $ kubectl get all --namespace default
    NAME                             READY   STATUS    RESTARTS   AGE
    pod/chrt-5753-7f5d576f95-pgr5g   1/1     Running   0          13m
    
    NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
    service/chrt-5753    ClusterIP   10.97.177.223   <none>        80/TCP    13m
    service/kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP   108d
    
    NAME                        READY   UP-TO-DATE   AVAILABLE   AGE
    deployment.apps/chrt-5753   1/1     1            1           13m
    
    NAME                                   DESIRED   CURRENT   READY   AGE
    replicaset.apps/chrt-5753-7f5d576f95   1         1         1       13m
    
    $  kubectl config set-context dind --namespace=new-ns
    Context "dind" modified.
    
    $ kubectl get namespaces
    NAME          STATUS   AGE
    default       Active   108d
    kube-public   Active   108d
    kube-system   Active   108d
    
    $ helm install chrt-5753-v2 chrt-5753/ 
    Error: create: failed to create: namespaces "new-ns" not found
    
    $ kubectl create namespace new-ns
    namespace/new-ns created
    
    $ kubectl get namespaces
    NAME          STATUS   AGE
    default       Active   108d
    kube-public   Active   108d
    kube-system   Active   108d
    new-ns        Active   16s
    
    $ helm install chrt-5753-v2 chrt-5753/ 
    NAME: chrt-5753-v2
    LAST DEPLOYED: 2019-05-27 16:46:18.555525534 +0100 IST m=+0.082804290
    NAMESPACE: new-ns
    STATUS: deployed
    
    NOTES:
    1. Get the application URL by running these commands:
      export POD_NAME=$(kubectl get pods -l "app=chrt-5753,release=chrt-5753-v2" -o jsonpath="{.items[0].metadata.name}")
      echo "Visit http://127.0.0.1:8080 to use your application"
      kubectl port-forward $POD_NAME 8080:80
    
    $ kubectl get all --namespace new-ns
    NAME                                READY   STATUS    RESTARTS   AGE
    pod/chrt-5753-v2-5fcbc484bd-8h8fn   1/1     Running   0          49s
    
    NAME                   TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
    service/chrt-5753-v2   ClusterIP   10.100.121.64   <none>        80/TCP    49s
    
    NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
    deployment.apps/chrt-5753-v2   1/1     1            1           49s
    
    NAME                                      DESIRED   CURRENT   READY   AGE
    replicaset.apps/chrt-5753-v2-5fcbc484bd   1         1         1       49s
  6. hickeyma commented on May 27, 2019

    @hickeyma
    Contributor

    The current code in v3 master does not specify the --namespace flag:

    $ helm install --help
    
    This command installs a chart archive.
    [....]
    Usage:
      helm install [NAME] [CHART] [flags]
    
    Flags:
          --ca-file string           verify certificates of HTTPS-enabled servers using this CA bundle
          --cert-file string         identify HTTPS client using this SSL certificate file
          --dependency-update        run helm dependency update before installing the chart
          --devel                    use development versions, too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored.
          --dry-run                  simulate an install
      -g, --generate-name            generate the name (and omit the NAME parameter)
      -h, --help                     help for install
          --key-file string          identify HTTPS client using this SSL key file
          --keyring string           location of public keys used for verification (default "/home/usr1/.gnupg/pubring.gpg")
          --name-template string     specify template used to name the release
          --no-hooks                 prevent hooks from running during install
          --password string          chart repository password where to locate the requested chart
    [....]

    It is subsequently ignored, and the context set namespace or default namespace is used instead:

    $ helm install chrt-5753-v4 chrt-5753/ --namespace=foo-ns 
    NAME: chrt-5753-v4
    LAST DEPLOYED: 2019-05-27 16:55:16.365404685 +0100 IST m=+0.075298110
    NAMESPACE: new-ns
    STATUS: deployed
    
    NOTES:
    1. Get the application URL by running these commands:
      export POD_NAME=$(kubectl get pods -l "app=chrt-5753,release=chrt-5753-v4" -o jsonpath="{.items[0].metadata.name}")
      echo "Visit http://127.0.0.1:8080 to use your application"
      kubectl port-forward $POD_NAME 8080:80
    
    $ kubectl get all --namespace new-ns
    NAME                                READY   STATUS    RESTARTS   AGE
    pod/chrt-5753-v2-5fcbc484bd-8h8fn   1/1     Running   0          9m12s
    pod/chrt-5753-v4-7d4cc6f574-4t46z   1/1     Running   0          14s
    
    NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
    service/chrt-5753-v2   ClusterIP   10.100.121.64    <none>        80/TCP    9m12s
    service/chrt-5753-v4   ClusterIP   10.99.132.241    <none>        80/TCP    14s
    
    NAME                           READY   UP-TO-DATE   AVAILABLE   AGE
    deployment.apps/chrt-5753-v2   1/1     1            1           9m12s
    deployment.apps/chrt-5753-v4   1/1     1            1           14s
    
    NAME                                      DESIRED   CURRENT   READY   AGE
    replicaset.apps/chrt-5753-v2-5fcbc484bd   1         1         1       9m12s
    replicaset.apps/chrt-5753-v4-7d4cc6f574   1         1         1       14s
    
    $ kubectl get namespaces
    NAME          STATUS   AGE
    default       Active   108d
    kube-public   Active   108d
    kube-system   Active   108d
    new-ns        Active   9m45s

    @bacongobbler @adamreese Is this how it should work in v3?

  7. bacongobbler commented on Jun 14, 2019

    @bacongobbler
    Member

    The change to remove the creation of the namespace during helm install was intentional. This was made to mimic the same behaviour as kubectl create --namespace foo -f deployment.yaml - namespaces are a global cluster resource and the user installing resources into that namespace may not have the proper administrative rights to install the namespace itself, as that implies you have full administrative rights to the cluster (as opposed to being bound to a role with restricted rights within a particular namespace). Without this change, users must have cluster admin rights to install a chart, and we want to ensure that administrators can ensure users only have a restricted set of roles applied to each install. This is also a big reason why TIller was removed in the first place.

    Additionally, there have been several asks in the community to allow modifying the namespace helm install creates (e.g. #3503), and the UX to support use cases like that would be incredibly painful to achieve. Offloading the namespace creation to a separate tool (perhaps a plugin?) provides users a way to solve these issues without imposing a restrictive user experience around these use cases.

    Note: I'm just relaying the information I know about this subject and why it was removed. I suggest asking @adamreese more about the justification for the removal.

  8. removed
    bug
    on Jun 14, 2019
  9. sudermanjr commented on Jun 18, 2019

    @sudermanjr

    I think delegating namespace creation to a different tool (or the user), is a great idea. More and more cluster-wide policies are being defined using namespace annotations and labels, which falls firmly outside the scope of a deployment tool such as helm.

    That being said, the current UX with the namespace flag is troublesome. In my initial cursory testing I am also seeing that the namespace flag is ignored and the current-context namespace is being used during a helm install command.

    └─ helm install --namespace demo demo reactiveops-incubator/basic-demo
    NAME: demo
    LAST DEPLOYED: 2019-06-18 12:27:11.270687 -0600 MDT m=+0.896967709
    NAMESPACE: sudermanjr
    STATUS: deployed
    
    NOTES:
    1. Get the application URL by running these commands:
      export POD_NAME=$(kubectl get pods --namespace sudermanjr -l "app.kubernetes.io/name=basic-demo,app.kubernetes.io/instance=demo" -o jsonpath="{.items[0].metadata.name}")
      echo "Visit http://127.0.0.1:8080 to use your application"
      kubectl port-forward $POD_NAME 8080:80
    
    └─ kubectl version --short
    Client Version: v1.11.9
    Server Version: v1.12.8
    
    └─ helm version
    version.BuildInfo{Version:"v3.0.0-alpha.1", GitCommit:"b9a54967f838723fe241172a6b94d18caf8bcdca", GitTreeState:"clean"}
    
  10. bacongobbler commented on Jun 18, 2019

    @bacongobbler
    Member

    That's great feedback, thank you @sudermanjr.

    In my initial cursory testing I am also seeing that the namespace flag is ignored and the current-context namespace is being used during a helm install command.

    Yeah, we're tracking that discussion in #5628 :)

  11. marckhouzam commented on Oct 23, 2019

    @marckhouzam
    Member

    Continuing from #5628.

    By supporting the auto-creation of the namespace, community members were proposing new features to Helm which would allow them to modify the namespace during creation, including attaching annotations, labels, policies, constraints, quotas, etc. The list goes on. [...]

    The same scoping issue and design flaws were apparent in helm init - users wanted to modify the Deployment and Service that Helm 2 would create server-side. [...]

    Thank you @bacongobbler for taking the time to give some historical justification. With this extra information it is easier to understand the maintainers' choice on this matter.

    [...] it wasn't done without consideration... or because we felt like breaking user's expectations for the fun of it. 😋

    I'm sure no one in the community would have thought that. The discussion was more about making the maintainers aware of users' reality. But it's clear you were well aware but had to make the hard decision. I respect that.

  12. ichekrygin commented on Oct 24, 2019

    @ichekrygin

    Interesting #5628 pre-dates this issue and more importantly is dedicated to the same topic:
    However, it seems @bacongobbler thinks otherwise :)

    As noted earlier, this discussion is getting off topic from the OP's original issue

  13. ichekrygin commented on Oct 24, 2019

    @ichekrygin

    @bacongobbler or any Helm3 maintainers/contributor comment on the desirability of having Helm3 as a "one-stop-shop"?

    For more context: #5628 (comment)

  14. bacongobbler commented on Oct 24, 2019

    @bacongobbler
    Member

    However, it seems @bacongobbler thinks otherwise :)

    @ichekrygin, it is incredibly frustrating having to repeat the same statement over and over. I will repeat myself one more time.

    I mentioned several times in that thread that the discussion is different than the one originally raised by the OP. The discussion in the first comment talks about the --namespace flag being ignored in earlier versions of Helm 3. Resources were being deployed in the default namespace regardless of what you provided to --namespace.

    Here's an excerpt from the first comment:

    It seems the latest helm3 from dev-v3 branch doesn't take the --namespace parameter.

    The only similarity with these two tickets is that they both are related to the --namespace flag.

    That's it.

    Hope that clears things up.

    or any Helm3 maintainers/contributor comment on the desirability of having Helm3 as a "one-stop-shop"?

    As I mentioned earlier:

    By supporting the auto-creation of the namespace, community members were proposing new features to Helm which would allow them to modify the namespace during creation, including attaching annotations, labels, policies, constraints, quotas, etc. The list goes on. #3503 is one such example. The creation and management of the namespace is clearly out of scope of helm install, whose goal was to fetch, unpack and install a chart into a cluster. Do one thing and do it well.

    [...]

    That being said, we are open to suggestions and are always happy to discuss alternative solutions.

    Do you have an alternative solution that does not fall to the same design flaws as indicated earlier?

  15. ichekrygin commented on Oct 24, 2019

    @ichekrygin

    Hi, @bacongobbler. Sorry to see you getting frustrated over this issue. As you observed the topics of both issues are very much related. Moreover, the issue (this issue) you recommend to continue having a conversation is also "Closed" (by you) on Jun 21, while the #5628 was remaining open till Sep 1, but, this IS getting off-topic :).

    By supporting the auto-creation of the namespace, community members were proposing new features to Helm which would allow them to modify the namespace during creation, including attaching annotations, labels, policies, constraints, quotas, etc.

    It is one thing to "reject" or "propose the alternatives" for the above-mentioned community member requests, it is totally another thing is to remove --namespace creation support from Helm altogether!

    I may have some alternative suggestions, but I would love to understand the issue and the motivation behind it first.

    Perhaps, a bit more insightful information could be to discuss the impact of preserving Helm2 create --namespace functionality in light of Helm3 design/implementation decision to leverage said namespace for the chart release information storage in the form of Kubernetes secret: sh.helm.release.v1.my-chart.v1 helm.sh/release.v1.

  16. bacongobbler commented on Oct 24, 2019

    @bacongobbler
    Member

    I explained the issue and the motivation for the removal of this feature several times in previous comments. Please read my previous comments more carefully.

  17. ichekrygin commented on Oct 24, 2019

    @ichekrygin

    Digging more into this.
    I was hoping that I could simply add a namespace.yaml definition into my chart as follow:

    apiVersion: v1
    kind: Namespace
    metadata:
      name: {{ .Release.Namespace }}
      labels:
        app: {{ template "foo.name" . }}
        chart: {{ template "foo.chart" . }}
        release: {{ .Release.Name }}

    Ideally nothing should prevent the namespace cration w/ all the "bells and whistles" that comminutiy members were proposing, as long as it is created in the previously documented order

    However, as I suspected, the reason why the "target" or {{ .Release.Namespace }} must exist before invoking install (and I suspect update) command is directly tied to the Helm3 storage implementation, which "relies" on the "target" namespace to store release information.
    https://github.com/helm/helm/blob/master/pkg/action/install.go#L254

    In very high-level understanding Helm3 performers following steps in the following order:

    • apply CRDs (crds do not require rendering, also, create collision errors are ignored)
    • render chart artifacts (other than crds)
    • save release information into the secret (requires target namespace), this is where: "namespace not found" error is triggered.
    • install rendred artifacts.
  18. ichekrygin commented on Oct 24, 2019

    @ichekrygin

    @bacongobbler, yes, you did. Unfortunately, for me, those did not fully make sense.

    After getting to the bottom of this, I guess the explanation that would make more sense (for me) would be the one you gave earlier (multiple times) plus, "oh, yeah... we are using "target" or {{ .Release.Namespace }} namespace in Helm3 for other reasons as well, like saving release information. Thus, it is problematic maintaining namespace creation via --namepace flag" or something like that.

    Either way, thank you for your help.

  19. javajon commented on Jan 6, 2020

    @javajon

    creation of the namespace during helm install was intentional.

    Agree with the change since the uninstall action did not remove the namespace making the uninstall feel dirty. If anyone considers a plugin, or other tool or means, and wants to take responsibility for creating the namespace, then the uninstall would need a delete transaction to counter the namespace create.

  20. ichekrygin commented on Jan 6, 2020

    @ichekrygin

    @javajon The "Cleanup" topic is relevant, yet I think it is of a wider scope specifically when it involves "cluster-level" components.
    Two points:

    1. Helm3 Consistency in handling CRD vs Namespace.
    2. The fact that a single namespace can be targetted by multiple HELM charts makes IMO a "compelling" case for having a "special" treatment for the Release Namespace (in line to what it used to be in Helm2 for namespaces, or what it is in Helm3 for CRD's)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    v3.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions