5.5.2.2. Creating a project
Use the Operator SDK CLI to create a project called nginx-operator.
Procedure
Create a directory for the project:
$ mkdir -p $HOME/projects/nginx-operatorChange to the directory:
$ cd $HOME/projects/nginx-operatorRun the
operator-sdk initcommand with thehelmplugin to initialize the project:$ operator-sdk init \ --plugins=helm \ --domain=example.com \ --group=demo \ --version=v1 \ --kind=Nginx注意By default, the
helmplugin initializes a project using a boilerplate Helm chart. You can use additional flags, such as the--helm-chartflag, to initialize a project using an existing Helm chart.The
initcommand creates thenginx-operatorproject specifically for watching a resource with API versionexample.com/v1and kindNginx.-
For Helm-based projects, the
initcommand generates the RBAC rules in theconfig/rbac/role.yamlfile based on the resources that would be deployed by the default manifest for the chart. Verify that the rules generated in this file meet the permission requirements of the Operator.
5.5.2.2.1. Existing Helm charts 复制链接链接已复制到粘贴板!
Instead of creating your project with a boilerplate Helm chart, you can alternatively use an existing chart, either from your local file system or a remote chart repository, by using the following flags:
-
--helm-chart -
--helm-chart-repo -
--helm-chart-version
If the --helm-chart flag is specified, the --group, --version, and --kind flags become optional. If left unset, the following default values are used:
| Flag | Value |
|---|---|
|
|
|
|
|
|
|
|
|
|
| Deduced from the specified chart |
If the --helm-chart flag specifies a local chart archive, for example example-chart-1.2.0.tgz, or directory, the chart is validated and unpacked or copied into the project. Otherwise, the Operator SDK attempts to fetch the chart from a remote repository.
If a custom repository URL is not specified by the --helm-chart-repo flag, the following chart reference formats are supported:
| Format | Description |
|---|---|
|
|
Fetch the Helm chart named |
|
| Fetch the Helm chart archive at the specified URL. |
If a custom repository URL is specified by --helm-chart-repo, the following chart reference format is supported:
| Format | Description |
|---|---|
|
|
Fetch the Helm chart named |
If the --helm-chart-version flag is unset, the Operator SDK fetches the latest available version of the Helm chart. Otherwise, it fetches the specified version. The optional --helm-chart-version flag is not used when the chart specified with the --helm-chart flag refers to a specific version, for example when it is a local path or a URL.
For more details and examples, run:
$ operator-sdk init --plugins helm --help