×

To allow clients outside of the cluster to verify the API server’s certificate, you can replace the default API server certificate with one that is issued by a CA that clients trust.

By default, the API server certificate is issued by an internal OKD cluster CA. As a result, clients outside of the cluster cannot verify the API server’s certificate.

In hosted control plane clusters, you can add as many custom certificates to your Kubernetes API Server as you need. However, do not add a certificate for the endpoint that worker nodes use to communicate with the control plane.

For more information, see "Configure a custom API server certificate in a hosted cluster".

Add an API server named certificate for the first time

The default API server certificate is issued by an internal OKD cluster Certificate Authority (CA).

You can add alternative certificates that the API server will return based on the fully qualified domain name (FQDN) requested by the client, for example when a reverse proxy or load balancer is used.

Adding a custom API server named certificate for the first time triggers the kube-apiserver-operator to roll out a new revision of the API server pods. Node reboots are not required.

Prerequisites
  • You must have a certificate for the FQDN and its corresponding private key. Each should be in a separate PEM format file.

  • The private key must be unencrypted.

  • The certificate must include the subjectAltName extension showing the FQDN.

  • The certificate file can contain one or more certificates in a chain. The certificate for the API server FQDN must be the first certificate in the file, followed by intermediate certificates, and ending with the root CA certificate.

Do not provide a named certificate for the internal load balancer (host name api-int.<cluster_name>.<base_domain>). Doing so will leave your cluster in a degraded state.

Procedure
  1. Log in to the CLI as the kubeadmin user:

    $ oc login -u kubeadmin -p <password> https://<fqdn>:6443

    where:

    <password>

    Specifies your cluster administrative password.

    <fqdn>

    Specifies the fully qualified domain name of the internal cluster API endpoint.

  2. Create a secret that contains the certificate chain and private key in the openshift-config namespace:

    $ oc create secret tls <secret_name> \
         --cert=<path_to_certificate_file> \
         --key=<path_to_private_key_file> \
         -n openshift-config

    where:

    <secret_name>

    Specifies the name of the new secret resource that will contain the cryptographic key pair.

    <path_to_certificate_file>

    Specifies the absolute local path to your custom certificate chain file.

    <path_to_private_key_file>

    Specifies the absolute local path to the unencrypted private key file associated with the certificate.

  3. Update the API server to reference the created secret resource:

    $ oc patch apiserver cluster --type=merge -p '
    {
      "spec": {
        "servingCerts": {
          "namedCertificates": [
            {
              "names": ["<fqdn>"],
              "servingCertificate": {
                "name": "<secret_name>"
              }
            }
          ]
        }
      }
    }'

    where:

    <fqdn>

    Specifies the fully qualified domain name for which the API server serves this custom certificate. Do not include a port number.

    <secret_name>

    Specifies the name of the secret you created in the previous step.

  4. Verify that a new revision of the Kubernetes API server rolls out by checking the operator status:

    $ oc get clusteroperators kube-apiserver

    The PROGRESSING status column will change to True while the API server operator deploys the new pod revision configured with your custom certificate. Do not interrupt the process or apply additional configuration updates while the rollout is underway. Continue only after the status returns to False and AVAILABLE reads True.

Update or renew an existing API server named certificate

Update or renew an expired or expiring named certificate that has already been configured in your cluster to avoid API availability issues. The API server pods dynamically detect and reload the updated certificate asset without disruption.

When an existing API server named certificate is renewed by updating its corresponding secret, a new revision of the Kubernetes API server pods does not roll out. Node reboots are not required.

If the renewed certificate is signed by a different root CA than the previous certificate, internal applications or custom pods that communicate with the API server might encounter X509 certificate validation errors. If these client workloads do not automatically hot-reload their truststores, you must manually restart them to force them to pick up the new certificate chain.

Prerequisites
  • You have the renewed certificate chain and private key files in PEM format.

  • The secret containing the old certificate already exists in the openshift-config namespace and is actively referenced by the apiserver/cluster configuration.

Procedure
  1. Log in to the CLI as the kubeadmin user.

  2. Update the existing secret resource in the openshift-config namespace with the newly issued certificate and private key:

    $ oc create secret tls <existing_secret_name> \
         --cert=<path_to_new_cert>.crt \
         --key=<path_to_new_key>.key \
         -n openshift-config \
         --dry-run=client -o yaml | oc replace -f -

    where:

    <existing_secret_name>

    Specifies the target name of the existing active secret that you are replacing.

    <path_to_new_cert>.crt

    Specifies the absolute local file system path to the renewed certificate chain file.

    <path_to_new_key>.key

    Specifies the absolute local file system path to the corresponding unencrypted private key file.

  3. Verify that the kube-apiserver pods successfully hot-reload the updated assets without initiating a new cluster deployment revision:

    $ oc get clusteroperators kube-apiserver

    Confirm that the PROGRESSING status column remains False. If the status changes to True, verify that your underlying apiserver/cluster resource parameters were not modified structural layout changes during the substitution.

Configure a custom API server certificate in a hosted cluster

To configure a custom certificate for the API server, specify the certificate details in the spec.configuration.apiServer section of your HostedCluster configuration.

You can configure a custom certificate during either Day 1 or Day 2 operations. However, because the service publishing strategy is immutable after you set it during hosted cluster creation, you must know what the hostname is for the Kubernetes API server that you plan to configure.

Prerequisites
  • You created a Kubernetes secret that contains your custom certificate in the management cluster. The secret contains the following keys:

    • tls.crt: The certificate

    • tls.key: The private key

  • If your HostedCluster configuration includes custom serving certificates via the spec.configuration.apiServer.servingCerts.namedCertificates specification, ensure that the Subject Alternative Names (SANs) of the certificate do not conflict with the external API server address. For example, depending on the hostname pattern used in your environment, the address might be in the following format: api.<cluster_name>.<domain>.

    The HostedCluster resource automatically includes the external API address in the default Kubernetes API server certificate SANs. If the same hostname is in both the custom certificate and the automatically generated Kubernetes API server certificate, the configuration is rejected to prevent TLS serving ambiguity.

    This validation applies to all service publishing strategies, including LoadBalancer and NodePort. The only exception is when you use Amazon Web Services (AWS) as the provider with Private or PublicAndPrivate endpoint access configurations, where the platform manages the SAN conflict.

  • The certificate must be valid for the external API endpoint.

  • The validity period of the certificate aligns with your cluster’s expected life cycle.

Procedure
  1. Create a secret with your custom certificate by entering the following command:

    $ oc create secret tls sample-hosted-kas-custom-cert \
      --cert=path/to/cert.crt \
      --key=path/to/key.key \
      -n <hosted_cluster_namespace>
  2. Update your HostedCluster configuration with the custom certificate details, as shown in the following example:

    spec:
      configuration:
        apiServer:
          servingCerts:
            namedCertificates:
            - names:
              - api-custom-cert-sample-hosted.sample-hosted.example.com
              servingCertificate:
                name: sample-hosted-kas-custom-cert
    • spec.configuration.apiServer.servingCerts.namedCertificates.names specifies the list of DNS names that the certificate is valid for.

    • spec.configuration.apiServer.servingCerts.namedCertificates.servingCertificate specifies the name of the secret that contains the custom certificate.

  3. Apply the changes to your HostedCluster configuration by entering the following command:

    $ oc apply -f <hosted_cluster_config>.yaml
Verification
  • Check the API server pods to ensure that the new certificate is mounted.

  • Test the connection to the API server by using the custom domain name.

  • Verify the certificate details in your browser or by using tools such as openssl.