istio.io/istio@v0.0.0-20240520182934-d79c90f27776/operator/README.md (about)

     1  [![Go Report Card](https://goreportcard.com/badge/github.com/istio/operator)](https://goreportcard.com/report/github.com/istio/operator)
     2  
     3  # Istio Operator
     4  
     5  The istio/operator repo is part of istio/istio from 1.5 onwards.
     6  You can [contribute](../CONTRIBUTING.md) by picking an
     7  [unassigned open issue](https://github.com/istio/istio/issues?q=is%3Aissue+is%3Aopen+label%3Aarea%2Fenvironments%2Foperator+no%3Aassignee),
     8  creating a [bug or feature request](../BUGS-AND-FEATURE-REQUESTS.md),
     9  or just coming to the weekly [Environments Working Group](https://github.com/istio/community/blob/master/WORKING-GROUPS.md)
    10  meeting to share your ideas.
    11  
    12  This document is an overview of how the operator works from a user perspective. For more details about the design and
    13  architecture and a code overview, see [ARCHITECTURE.md](../architecture/environments/operator.md).
    14  
    15  ## Introduction
    16  
    17  The operator uses the [IstioOperator API](https://github.com/istio/api/blob/master/operator/v1alpha1/operator.proto), which has
    18  three main components:
    19  
    20  - [MeshConfig](https://github.com/istio/api/blob/master/mesh/v1alpha1/config.proto) for runtime config consumed directly by Istio
    21  control plane components.
    22  - [Component configuration API](https://github.com/istio/api/blob/00671adacbea20f941cb20cce021bc63cbad1840/operator/v1alpha1/operator.proto#L42-L93), for managing
    23  K8s settings like resources, auto scaling, pod disruption budgets and others defined in the
    24  [KubernetesResourceSpec](https://github.com/istio/api/blob/00671adacbea20f941cb20cce021bc63cbad1840/operator/v1alpha1/operator.proto#L217-L271)
    25  for Istio core and addon components.
    26  - The legacy
    27  [Helm installation API](https://github.com/istio/istio/blob/master/operator/pkg/apis/istio/v1alpha1/values_types.proto) for backwards
    28  compatibility.
    29  
    30  Some parameters will temporarily exist both the component configuration and legacy Helm APIs - for example, K8s
    31  resources. However, the Istio community recommends using the first API as it is more consistent, is validated,
    32  and will naturally follow the graduation process for APIs while the same parameters in the configuration API are planned
    33  for deprecation.
    34  
    35  [Profiles](https://istio.io/docs/setup/kubernetes/additional-setup/config-profiles/), are provided as a starting point for
    36  an Istio install and can be customized by creating customization overlay files or passing parameters through the
    37  --set flag. For example, to select the minimal profile:
    38  
    39  ```yaml
    40  # minimal.yaml
    41  
    42  apiVersion: install.istio.io/v1alpha1
    43  kind: IstioOperator
    44  spec:
    45    profile: minimal
    46  ```
    47  
    48  If you don't specify a configuration profile, Istio is installed using the `default` configuration profile. All
    49  profiles listed in istio.io are available by default, or `profile:` can point to a local file path to reference a custom
    50  profile base to use as a starting point for customization. See the [API reference](https://github.com/istio/api/blob/master/operator/v1alpha1/operator.proto)
    51  for details.
    52  
    53  ## Developer quick start
    54  
    55  The quick start describes how to install and use the operator `mesh` CLI command and/or controller.
    56  
    57  ### CLI
    58  
    59  To build the operator CLI, simply:
    60  
    61  ```bash
    62  make build
    63  ```
    64  
    65  Ensure the created binary is in your PATH to run the examples below.
    66  
    67  ### Controller (in cluster)
    68  
    69  Building a custom controller requires a Dockerhub (or similar) account. To build using the container based build:
    70  
    71  ```bash
    72  HUB=docker.io/<your-account> TAG=latest make docker.operator
    73  ```
    74  
    75  This builds the controller binary and docker file, and pushes the image to the specified hub with the `latest` tag.
    76  Once the images are pushed, configure kubectl to point to your cluster and install the controller.
    77  
    78  Install the controller manifest:
    79  
    80  ```bash
    81  istioctl operator init --hub docker.io/<your-account> --tag latest
    82  kubectl create ns istio-system
    83  kubectl apply -f operator/samples/default-install.yaml
    84  ```
    85  
    86  This installs the controller into the cluster in the istio-operator namespace. The controller in turns installs
    87  the Istio control plane into the istio-system namespace by default.
    88  
    89  ### Controller (running locally)
    90  
    91  1. Set env $WATCH_NAMESPACE (default value is "istio-system") and $LEADER_ELECTION_NAMESPACE (default value is "istio-operator")
    92  
    93  1. Create the `WATCH_NAMESPACE` and `LEADER_ELECTION_NAMESPACE` if they are not created yet.
    94  
    95  ```bash
    96  kubectl create ns $WATCH_NAMESPACE --dry-run -o yaml | kubectl apply -f -
    97  kubectl create ns $LEADER_ELECTION_NAMESPACE --dry-run -o yaml | kubectl apply -f -
    98  ```
    99  
   100  1. From the istio repo root directory, run `go run ./operator/cmd/operator/*.go server`
   101  
   102  To use Remote debugging with IntelliJ, replace above step 2 with following:
   103  
   104  1. From `./operator/cmd/operator` path run
   105  `
   106  dlv debug --headless --listen=:2345 --api-version=2 -- server
   107  `.
   108  
   109  1. In IntelliJ, create a new Go Remote debug configuration with default settings.
   110  
   111  1. Start debugging process and verify it is working. For example, try adding a breakpoint at Reconcile logic and apply a new CR.
   112  
   113  ### Relationship between the CLI and controller
   114  
   115  The CLI and controller share the same API and codebase for generating manifests from the API. You can think of the
   116  controller as the CLI command `istioctl install` running in a loop in a pod in the cluster and using the config
   117  from the in-cluster IstioOperator custom resource (CR).
   118  There are two major differences:
   119  
   120  1. The controller does not accept any dynamic user config through flags. All user interaction is through the
   121  IstioOperator CR.
   122  1. The controller has additional logic that mirrors istioctl commands like upgrade, but is driven from the declarative
   123  API rather than command line.
   124  
   125  ### Quick tour of CLI commands
   126  
   127  #### Flags
   128  
   129  The `istioctl` command supports the following flags:
   130  
   131  - `dry-run`: console output only, nothing applied to cluster or written to files.
   132  - `verbose`: display entire manifest contents and other debug info (default is false).
   133  - `set`: select profile or override profile defaults
   134  
   135  #### Basic default manifest
   136  
   137  The following command generates a manifest with the compiled-in `default` profile and charts:
   138  
   139  ```bash
   140  istioctl manifest generate
   141  ```
   142  
   143  You can see these sources for the compiled-in profiles and charts in the repo under `manifests/`. These profiles and charts are also included in the Istio release tar.
   144  
   145  #### Output to dirs
   146  
   147  The output of the manifest is concatenated into a single file. To generate a directory hierarchy with subdirectory
   148  levels representing a child dependency, use the following command:
   149  
   150  ```bash
   151  istioctl manifest generate -o istio_manifests
   152  ```
   153  
   154  Use depth first search to traverse the created directory hierarchy when applying your YAML files. This is needed for
   155  correct sequencing of dependencies. Child manifest directories must wait for their parent directory to be fully applied,
   156  but not their sibling manifest directories.
   157  
   158  #### Just apply it for me
   159  
   160  The following command generates the manifests and applies them in the correct dependency order, waiting for the
   161  dependencies to have the needed CRDs available:
   162  
   163  ```bash
   164  istioctl install
   165  ```
   166  
   167  #### Review the values of a configuration profile
   168  
   169  The following commands show the values of a configuration profile:
   170  
   171  ```bash
   172  # show available profiles
   173  istioctl profile list
   174  
   175  # show the values in demo profile
   176  istioctl profile dump demo
   177  
   178  # show the values after a customization file is applied
   179  istioctl profile dump -f samples/pilot-k8s.yaml
   180  
   181  # show differences between the default and demo profiles
   182  istioctl profile dump default > 1.yaml
   183  istioctl profile dump demo > 2.yaml
   184  istioctl profile diff 1.yaml 2.yaml
   185  
   186  # show the differences in the generated manifests between the default profile and a customized install
   187  istioctl manifest generate > 1.yaml
   188  istioctl manifest generate -f samples/pilot-k8s.yaml > 2.yaml
   189  istioctl manifest diff 1.yam1 2.yaml
   190  ```
   191  
   192  The profile dump sub-command supports a couple of useful flags:
   193  
   194  - `config-path`: select the root for the configuration subtree you want to see e.g. just show Pilot:
   195  
   196  ```bash
   197  istioctl profile dump --config-path components.pilot
   198  ```
   199  
   200  - `filename`: set parameters in the configuration file before dumping the resulting profile e.g. show the pilot k8s overlay settings:
   201  
   202  ```bash
   203  istioctl profile dump --filename samples/pilot-k8s.yaml
   204  ```
   205  
   206  #### Select a specific configuration profile
   207  
   208  The simplest customization is to select a profile different to `default` e.g. `minimal`. See [manifests/profiles/minimal.yaml](../manifests/profiles/minimal.yaml):
   209  
   210  ```yaml
   211  # minimal-install.yaml
   212  apiVersion: install.istio.io/v1alpha1
   213  kind: IstioOperator
   214  spec:
   215    profile: minimal
   216  ```
   217  
   218  Use `istioctl` to generate the manifests for the new configuration profile:
   219  
   220  ```bash
   221  istioctl manifest generate -f manifests/profiles/minimal.yaml
   222  ```
   223  
   224  After running the command, the Helm charts are rendered using `manifests/profiles/minimal.yaml`.
   225  
   226  ##### --set syntax
   227  
   228  The CLI `--set` option can be used to override settings within the profile.
   229  
   230  For example, to enable auto mTLS, use `istioctl manifest generate --set values.global.mtls.auto=true --set values.global.controlPlaneSecurityEnabled=true`
   231  
   232  To override a setting that includes dots, escape them with a backslash (\).  Your shell may require enclosing quotes.
   233  
   234  ``` bash
   235  istioctl manifest generate --set "values.sidecarInjectorWebhook.injectedAnnotations.container\.apparmor\.security\.beta\.kubernetes\.io/istio-proxy=runtime/default"
   236  ```
   237  
   238  To override a setting that is part of a list, use brackets.
   239  
   240  ``` bash
   241  istioctl manifest generate --set values.gateways.istio-ingressgateway.enabled=false \
   242  --set values.gateways.istio-egressgateway.enabled=true \
   243  --set 'values.gateways.istio-egressgateway.secretVolumes[0].name'=egressgateway-certs \
   244  --set 'values.gateways.istio-egressgateway.secretVolumes[0].secretName'=istio-egressgateway-certs \
   245  --set 'values.gateways.istio-egressgateway.secretVolumes[0].mountPath'=/etc/istio/egressgateway-certs
   246  ```
   247  
   248  #### Install from file path
   249  
   250  The compiled in charts and profiles are used by default, but you can specify a file path, for example:
   251  
   252  ```yaml
   253  apiVersion: install.istio.io/v1alpha1
   254  kind: IstioOperator
   255  spec:
   256    profile: /usr/home/bob/go/src/github.com/ostromart/istio-installer/data/profiles/default.yaml
   257    installPackagePath: /usr/home/bob/go/src/github.com/ostromart/istio-installer/data/charts/
   258  ```
   259  
   260  You can mix and match these approaches. For example, you can use a compiled-in configuration profile with charts in your
   261  local file system.
   262  
   263  #### Check diffs of manifests
   264  
   265  The following command takes two manifests and output the differences in a readable way. It can be used to compare between the manifests generated by operator API and helm directly:
   266  
   267  ```bash
   268  istioctl manifest diff ./out/helm-template/manifest.yaml ./out/mesh-manifest/manifest.yaml
   269  ```
   270  
   271  ### New API customization
   272  
   273  The [new platform level installation API](https://github.com/istio/api/blob/master/operator/v1alpha1/operator.proto)
   274  defines install time parameters like component and enablement and namespace, and K8s settings like resources, HPA spec etc. in a structured way.
   275  The simplest customization is to turn components on and off. For example, to turn on cni ([samples/cni-on.yaml](samples/cni-on.yaml):
   276  
   277  ```yaml
   278  apiVersion: install.istio.io/v1alpha1
   279  kind: IstioOperator
   280  spec:
   281    components:
   282      cni:
   283        enabled: true
   284  ```
   285  
   286  The operator validates the configuration and automatically detects syntax errors. If you are
   287  using Helm values that are incompatible, the schema validation used in the operator may reject input that is valid for
   288  Helm.
   289  Each Istio component has K8s settings, and these can be overridden from the defaults using official K8s APIs rather than
   290  Istio defined schemas ([samples/pilot-k8s.yaml](samples/pilot-k8s.yaml)):
   291  
   292  ```yaml
   293  apiVersion: install.istio.io/v1alpha1
   294  kind: IstioOperator
   295  spec:
   296    components:
   297      pilot:
   298        k8s:
   299          resources:
   300            requests:
   301              cpu: 1000m # override from default 500m
   302              memory: 4096Mi # ... default 2048Mi
   303          hpaSpec:
   304            maxReplicas: 10 # ... default 5
   305            minReplicas: 2  # ... default 1
   306          nodeSelector: # ... default empty
   307            master: "true"
   308          tolerations: # ... default empty
   309          - key: dedicated
   310            operator: Exists
   311            effect: NoSchedule
   312          - key: CriticalAddonsOnly
   313            operator: Exists
   314  ```
   315  
   316  The K8s settings are defined in detail in the
   317  [operator API](https://github.com/istio/api/blob/master/operator/v1alpha1/operator.proto).
   318  The settings are the same for all components, so a user can configure pilot K8s settings in exactly the same, consistent
   319  way as galley settings. Supported K8s settings currently include:
   320  
   321  - [resources](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#resource-requests-and-limits-of-pod-and-container)
   322  - [readiness probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/)
   323  - [replica count](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
   324  - [HorizontalPodAutoscaler](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/)
   325  - [PodDisruptionBudget](https://kubernetes.io/docs/concepts/workloads/pods/disruptions/#how-disruption-budgets-work)
   326  - [pod annotations](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/)
   327  - [container environment variables](https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/)
   328  - [ImagePullPolicy](https://kubernetes.io/docs/concepts/containers/images/)
   329  - [priority class name](https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#priorityclass)
   330  - [node selector](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector)
   331  - [toleration](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/)
   332  - [affinity and anti-affinity](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity)
   333  - [deployment strategy](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
   334  - [service annotations](https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/)
   335  - [service spec](https://kubernetes.io/docs/concepts/services-networking/service/)
   336  - [pod securityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-pod)
   337  
   338  All of these K8s settings use the K8s API definitions, so [K8s documentation](https://kubernetes.io/docs/concepts/) can
   339  be used for reference. All K8s overlay values are also validated in the operator.
   340  
   341  ### Customizing the old values.yaml API
   342  
   343  The new platform install API above deals with K8s level settings. The remaining values.yaml parameters deal with Istio
   344  control plane operation rather than installation. For the time being, the operator just passes these through to the Helm
   345  charts unmodified (but validated through a
   346  [schema](pkg/apis/istio/v1alpha1/values_types.proto)). Values.yaml settings
   347  are overridden the same way as the new API, though a customized CR overlaid over default values for the selected
   348  profile. Here's an example of overriding some global level default values ([samples/values-global.yaml](samples/values-global.yaml)):
   349  
   350  ```yaml
   351  apiVersion: install.istio.io/v1alpha1
   352  kind: IstioOperator
   353  spec:
   354    profile: sds
   355    values:
   356      global:
   357        logging:
   358          level: "default:warning" # override from info
   359  ```
   360  
   361  Values overrides can also be specified for a particular component
   362   ([samples/values-pilot.yaml](samples/values-pilot.yaml)):
   363  
   364  ```yaml
   365  apiVersion: install.istio.io/v1alpha1
   366  kind: IstioOperator
   367  spec:
   368    values:
   369      pilot:
   370        traceSampling: 0.1 # override from 1.0
   371  ```
   372  
   373  ### Advanced K8s resource overlays
   374  
   375  Advanced users may occasionally have the need to customize parameters (like container command line flags) which are not
   376  exposed through either of the installation or configuration APIs described in this document. For such cases, it's
   377  possible to overlay the generated K8s resources before they are applied with user-defined overlays. For example, to
   378  override some container level values in the Pilot container  ([samples/pilot-advanced-override.yaml](samples/pilot-advanced-override.yaml)):
   379  
   380  ```yaml
   381  apiVersion: install.istio.io/v1alpha1
   382  kind: IstioOperator
   383  spec:
   384    components:
   385      pilot:
   386        k8s:
   387          overlays:
   388          - kind: Deployment
   389            name: istio-pilot
   390            patches:
   391            - path: spec.template.spec.containers.[name:discovery].args.[30m]
   392              value: "60m" # OVERRIDDEN
   393            - path: spec.template.spec.containers.[name:discovery].ports.[containerPort:8080].containerPort
   394              value: 8090 # OVERRIDDEN
   395            - path: 'spec.template.spec.volumes[100]' #push to the list
   396              value:
   397                configMap:
   398                  name: my-config-map
   399                name: my-volume-name
   400            - path: 'spec.template.spec.containers[0].volumeMounts[100]'
   401              value:
   402                mountPath: /mnt/path1
   403                name: my-volume-name
   404          - kind: Service
   405            name: istio-pilot
   406            patches:
   407            - path: spec.ports.[name:grpc-xds].port
   408              value: 15099 # OVERRIDDEN
   409  ```
   410  
   411  The user-defined overlay uses a path spec that includes the ability to select list items by key. In the example above,
   412  the container with the key-value "name: discovery" is selected from the list of containers, and the command line
   413  parameter with value "30m" is selected to be modified. The advanced overlay capability is described in more detail in
   414  the spec.
   415  
   416  ## Interaction with controller
   417  
   418  The controller shares the same API as the operator CLI, so it's possible to install any of the above examples as a CR
   419  in the cluster in the istio-system namespace and the controller will react to it with the same outcome as running
   420  `istioctl install -f <path-to-custom-resource-file>`.
   421  
   422  ## Architecture
   423  
   424  See [ARCHITECTURE.md](../architecture/environments/operator.md)