Este conteúdo não está disponível no idioma selecionado.
Chapter 4. OpenShift Service Mesh and cert-manager
The cert-manager tool is a solution for X.509 certificate management on Kubernetes. It delivers a unified API to integrate applications with private or public key infrastructure (PKI), such as Vault, Google Cloud Certificate Authority Service, Let’s Encrypt, and other providers.
The cert-manager tool must be installed before you create and install your Istio resource.
The cert-manager tool ensures the certificates are valid and up-to-date by attempting to renew certificates at a configured time before they expire.
4.1. About integrating Service Mesh with cert-manager and istio-csr Copiar o linkLink copiado para a área de transferência!
The cert-manager tool provides integration with Istio through an external agent called istio-csr. The istio-csr agent handles certificate signing requests (CSR) from Istio proxies and the controlplane in the following ways:
- Verifying the identity of the workload.
- Creating a CSR through cert-manager for the workload.
The cert-manager tool then creates a CSR to the configured CA Issuer, which signs the certificate.
Red Hat provides support for integrating with istio-csr and cert-manager. Red Hat does not provide direct support for the istio-csr or the community cert-manager components. The use of community cert-manager shown here is for demonstration purposes only.
Prerequisites
One of these versions of cert-manager:
- Red Hat cert-manager Operator 1.10 or later
- community cert-manager Operator 1.11 or later
- cert-manager 1.11 or later
- Red Hat OpenShift Service Mesh 3.0 or later
-
An
IstioCNIinstance is running in the cluster -
Istio CLI (
istioctl) tool is installed -
jqis installed - Helm is installed
4.2. Installing cert-manager Copiar o linkLink copiado para a área de transferência!
You can integrate cert-manager with OpenShift Service Mesh by deploying istio-csr and then creating an Istio resource that uses the istio-csr agent to process workload and control plane certificate signing requests. This example creates a self-signed Issuer, but any other Issuer can be used instead.
You must install cert-manager before installing your Istio resource.
Procedure
Create the
istio-systemnamespace by running the following command:oc create namespace istio-system
$ oc create namespace istio-systemCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the root issuer by creating an
Issuerobject in a YAML file.Create an
Issuerobject similar to the following example:Example
issuer.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the objects by running the following command:
oc apply -f issuer.yaml
$ oc apply -f issuer.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Wait for the
istio-cacertificate to contain the "Ready" status condition by running the following command:oc wait --for=condition=Ready certificates/istio-ca -n istio-system
$ oc wait --for=condition=Ready certificates/istio-ca -n istio-systemCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Copy the
istio-cacertificate to thecert-managernamespace so it can be used by istio-csr:Copy the secret to a local file by running the following command:
oc get -n istio-system secret istio-ca -o jsonpath='{.data.tls\.crt}' | base64 -d > ca.pem$ oc get -n istio-system secret istio-ca -o jsonpath='{.data.tls\.crt}' | base64 -d > ca.pemCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a secret from the local certificate file in the
cert-managernamespace by running the following command:oc create secret generic -n cert-manager istio-root-ca --from-file=ca.pem=ca.pem
$ oc create secret generic -n cert-manager istio-root-ca --from-file=ca.pem=ca.pemCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Next steps
To install istio-csr, you must follow the istio-csr installation instructions for the type of update strategy you want. By default, spec.updateStrategy is set to InPlace when you create and install your Istio resource. You create and install your Istio resource after you install istio-csr.
4.2.1. Installing the istio-csr agent by using the in place update strategy Copiar o linkLink copiado para a área de transferência!
Istio resources use the in place update strategy by default. Follow this procedure if you plan to leave spec.updateStrategy as InPlace when you create and install your Istio resource.
Procedure
Add the Jetstack charts repository to your local Helm repository by running the following command:
helm repo add jetstack https://charts.jetstack.io --force-update
$ helm repo add jetstack https://charts.jetstack.io --force-updateCopy to Clipboard Copied! Toggle word wrap Toggle overflow Install the
istio-csrchart by running the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Next steps
4.2.2. Installing the istio-csr agent by using the revision based update strategy Copiar o linkLink copiado para a área de transferência!
Istio resources use the in place update strategy by default. Follow this procedure if you plan to change spec.updateStrategy to RevisionBased when you create and install your Istio resource.
Procedure
-
Specify all the Istio revisions to your
istio-csrdeployment. See "istio-csr deployment". Add the Jetstack charts to your local Helm repository by running the following command:
helm repo add jetstack https://charts.jetstack.io --force-update
$ helm repo add jetstack https://charts.jetstack.io --force-updateCopy to Clipboard Copied! Toggle word wrap Toggle overflow Install the
istio-csrchart with your revision name by running the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteRevision names use the following format,
<istio-name>-v<major_version>-<minor_version>-<patch_version>. For example:default-v1-24-3.
Additional resources
Next steps
4.2.3. Installing your Istio resource Copiar o linkLink copiado para a área de transferência!
After you have installed istio-csr by following the procedure for either an in place or revision based update strategy, you can install the Istio resource.
You need to disable Istio’s built in CA server and tell istiod to use the istio-csr CA server. The istio-csr CA server issues certificates for both istiod and user workloads.
Procedure
Create the
Istioobject as shown in the following example:Example
istio.yamlobjectCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you installed your CSR agent with a revision based update strategy, then you need to add the following to your
Istioobject YAML:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
Istioresource by running the following command:oc apply -f istio.yaml
$ oc apply -f istio.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Wait for the
Istioobject to become ready by running the following command:oc wait --for=condition=Ready istios/default -n istio-system
$ oc wait --for=condition=Ready istios/default -n istio-systemCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.2.4. Verifying cert-manager installation Copiar o linkLink copiado para a área de transferência!
You can use the sample httpbin service and sleep application to check communication between the workloads. You can also check the workload certificate of the proxy to verify that the cert-manager tool is installed correctly.
Procedure
Create the
samplenamespace by running the following command:oc new-project sample
$ oc new-project sampleCopy to Clipboard Copied! Toggle word wrap Toggle overflow Find your active Istio revision by running the following command:
oc get istios default -o jsonpath='{.status.activeRevisionName}'$ oc get istios default -o jsonpath='{.status.activeRevisionName}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the injection label for your active revision to the
samplenamespace by running the following command:oc label namespace sample istio.io/rev=<your-active-revision-name> --overwrite=true
$ oc label namespace sample istio.io/rev=<your-active-revision-name> --overwrite=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the sample
httpbinservice by running the following command:oc apply -n sample -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/httpbin/httpbin.yaml
$ oc apply -n sample -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/httpbin/httpbin.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the sample
sleepapplication by running the following command:oc apply -n sample -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/sleep/sleep.yaml
$ oc apply -n sample -f https://raw.githubusercontent.com/openshift-service-mesh/istio/refs/heads/master/samples/sleep/sleep.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Wait for both applications to become ready by running the following command:
oc rollout status -n sample deployment httpbin sleep
$ oc rollout status -n sample deployment httpbin sleepCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that
sleepapplication can access thehttpbinservice by running the following command:oc exec "$(oc get pod -l app=sleep -n sample \ -o jsonpath={.items..metadata.name})" -c sleep -n sample -- \ curl http://httpbin.sample:8000/ip -s -o /dev/null \ -w "%{http_code}\n"$ oc exec "$(oc get pod -l app=sleep -n sample \ -o jsonpath={.items..metadata.name})" -c sleep -n sample -- \ curl http://httpbin.sample:8000/ip -s -o /dev/null \ -w "%{http_code}\n"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example of a successful output
200
200Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the following command to print the workload certificate for the
httpbinservice and verify the output:istioctl proxy-config secret -n sample $(oc get pods -n sample -o jsonpath='{.items..metadata.name}' --selector app=httpbin) -o json | jq -r '.dynamicActiveSecrets[0].secret.tlsCertificate.certificateChain.inlineBytes' | base64 --decode | openssl x509 -text -noout$ istioctl proxy-config secret -n sample $(oc get pods -n sample -o jsonpath='{.items..metadata.name}' --selector app=httpbin) -o json | jq -r '.dynamicActiveSecrets[0].secret.tlsCertificate.certificateChain.inlineBytes' | base64 --decode | openssl x509 -text -nooutCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
... Issuer: O = cert-manager + O = cluster.local, CN = istio-ca ... X509v3 Subject Alternative Name: URI:spiffe://cluster.local/ns/sample/sa/httpbin
... Issuer: O = cert-manager + O = cluster.local, CN = istio-ca ... X509v3 Subject Alternative Name: URI:spiffe://cluster.local/ns/sample/sa/httpbinCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3. Updating istio-csr agents with revision-based update strategies Copiar o linkLink copiado para a área de transferência!
If you deployed your Istio resource using the revision based update strategy, you must pass all revisions each time you update your control plane. You must perform the update in the following order:
-
Update the
istio-csrdeployment with the new revision. -
Update the value of
Istio.spec.versionparameter/field.
Example update for RevisionBased control plane
In this example, the controlplane is being updated from v1.24.0 to 1.24.1.
Update the
istio-csrdeployment with the new revision by running the following command:helm upgrade cert-manager-istio-csr jetstack/cert-manager-istio-csr \ --wait \ --reuse-values \ --set "app.istio.revisions={<old_revision>,<new_revision>}"$ helm upgrade cert-manager-istio-csr jetstack/cert-manager-istio-csr \ --wait \ --reuse-values \ --set "app.istio.revisions={<old_revision>,<new_revision>}"Copy to Clipboard Copied! Toggle word wrap Toggle overflow where:
old_revision-
Specifies the old revision in the
<istio-name>-v<major_version>-<minor_version>-<patch_version>format. For example:default-v1-24-0. new_revision-
Specifies the new revision in the
<istio-name>-v<major_version>-<minor_version>-<patch_version>format. For example:default-v1-24-1.
Update the
istio.spec.versionin theIstioobject similar to the following example:Example
istio.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Update to the new revision prefixed with the letter v, such as
v1.24.1
Remove the old revision from your
istio-csrdeployment by running the following command:Copy to Clipboard Copied! Toggle word wrap Toggle overflow