Is there a way to create RBAC and network policies in a declarative way

Hi

As far you know, there are many ways with kubectl to get the template yamls done, in order to create many objects in Kuberenetes. But I’m not so sure if I can create rbac and/or network policies in a declarative way, instead of just hardcoding the yaml file. Is not necesary that gets all the variables inserted by terminal input, just with having a default template I’m more than happy.

Have a nice day!

Declarative is the YAML, because you are declaring a resource manifest.

Imperative is the command line way - you can kubectl run single pods, and you can kubectl create only these

1 Like

Hi @Alistair_KodeKloud

So you can’t create the template by the command line for those cases. Do you know why the kubernetes development team doesn’t implement the functions to create RBAC and network policies in kubectl create command ? I find so elegant and convenient that Kubernetes allow to create the “templates” by the command line. I don’t know if they don’t want to implement the rbac and net cases because of security issues with k8s. For one apporach I think if you create some kind of automation for those yaml file, there could be less errors by the admins, but maybe there is something that I’m not seeing. I’m guessing that Kubernetes have some parser tree checker to check the syntax and semantics of the yaml files. Why no use the parser tree to generate default rbac and net policies ? So maybe I’m thinking that I’m missing something from the whole picture.

Thanks for the help, and for the correction. In my native language the words declarative and imperative have a very similiar sounding word, but with the opposite meaning. Thanks for let me notice that.

Have nice day

No idea. Would suggest you raise a question here: Issues · kubernetes/kubectl · GitHub

But then in the real world, nobody creates resources imperatively (except for emergency fixes), nor do they deploy applications on production clusters using just YAML manifests alone. Helm is the most popular way to package up entire applications. There are many ways to test the validity of your helm charts prior to production deployment.

1 Like

Read this kubectl create NetworkPolicy · Issue #1240 · kubernetes/kubectl · GitHub.
This `kubectl create` alternatives · Issue #914 · kubernetes/kubectl · GitHub
And this GitHub - eddiezane/kubectl-generate: kubectl generate is a proof on concept that attempts to tackle scaffolding yaml manifests

1 Like

Hi

Thanks @Alistair_KodeKloud for let me know that Helm have a test validation for the charts. I’m focusing now in getting in k8s to get the CKA, but I know that after that I need to learn Helm to use the go extensions in the yaml files that Helm provides. So I know a little about of Helm world in general. As far as I know there is also a package manager, so I maybe I thinking that Helm also helps to troubleshoot in differente ways than k8s alone. I know that Helm uses the same syntax for creating the yaml files, with exception of the go functions, that works very in the similar way that the Hugo static website generator. What’s is the average to learn Helm ? It seems that in a few weeks one could master it after learning k8s, but I’m not so sure if I’m missing something in the learning curve.

Thanks @tsanghan for let me know, that they are actually creating the kubectl generate command to create the templates for yaml files. Very Appreciated as alistair.

Have both a nice week