Skip to content
logo
Percona Operator for MySQL
Defining environment variables
Initializing search
    percona/k8spxc-docs
    percona/k8spxc-docs
    • Welcome
      • System Requirements
      • Design and architecture
      • Comparison with other solutions
      • Install with Helm
      • Install with kubectl
      • Install on Minikube
      • Install on Google Kubernetes Engine (GKE)
      • Install on Amazon Elastic Kubernetes Service (AWS EKS)
      • Install on Microsoft Azure Kubernetes Service (AKS)
      • Install on OpenShift
      • Generic Kubernetes installation
      • Multi-cluster and multi-region deployment
      • Application and system users
      • Changing MySQL Options
      • Anti-affinity and tolerations
      • Labels and annotations
      • Local Storage support
      • Defining environment variables
      • Load Balancing with HAProxy
      • Load Balancing with ProxySQL
      • Transport Encryption (TLS/SSL)
      • Data at rest encryption
      • Telemetry
      • Backup and restore
      • Upgrade Database and Operator
      • Horizontal and vertical scaling
      • Monitor with Percona Monitoring and Management (PMM)
      • Add sidecar containers
      • Restart or pause the cluster
      • Crash recovery
      • Debug and troubleshoot
      • How to install Percona XtraDB Cluster in multi-namespace (cluster-wide) mode
      • How to upgrade Percona XtraDB Cluster manually
      • How to use private registry
      • Custom Resource options
      • Percona certified images
      • Operator API
      • Frequently Asked Questions
      • Old releases (documentation archive)
      • Release notes index
      • Percona Operator for MySQL based on Percona XtraDB Cluster 1.12.0 (2022-12-07)
      • Percona Operator for MySQL based on Percona XtraDB Cluster 1.11.0 (2022-06-03)
      • Percona Distribution for MySQL Operator 1.10.0 (2021-11-24)
      • Percona Distribution for MySQL Operator 1.9.0 (2021-08-09)
      • Percona Kubernetes Operator for Percona XtraDB Cluster 1.8.0 (2021-05-26)
      • Percona Kubernetes Operator for Percona XtraDB Cluster 1.7.0 (2021-02-02)
      • Percona Kubernetes Operator for Percona XtraDB Cluster 1.6.0 (2020-09-09)
      • Percona Kubernetes Operator for Percona XtraDB Cluster 1.5.0 (2020-07-21)
      • Percona Kubernetes Operator for Percona XtraDB Cluster 1.4.0 (2020-04-29)
      • Percona Kubernetes Operator for Percona XtraDB Cluster 1.3.0 (2020-01-06)
      • Percona Kubernetes Operator for Percona XtraDB Cluster 1.2.0 (2019-09-20)
      • Percona Kubernetes Operator for Percona XtraDB Cluster 1.1.0 (2019-07-15)
      • Percona Kubernetes Operator for Percona XtraDB Cluster 1.0.0 (2019-05-29)

    Define environment variables¶

    Sometimes you need to define new environment variables to provide additional configuration for the components of your cluster. For example, you can use it to customize the configuration of HAProxy, or to add additional options for PMM Client.

    The Operator can store environment variables in Kubernetes Secrets. Here is an example with several HAProxy options:

    apiVersion: v1
    kind: Secret
    metadata:
      name: my-env-var-secrets
    type: Opaque
    data:
      HA_CONNECTION_TIMEOUT: MTAwMA==
      OK_IF_DONOR: MQ==
      HA_SERVER_OPTIONS: Y2hlY2sgaW50ZXIgMzAwMDAgcmlzZSAxIGZhbGwgNSB3ZWlnaHQgMQ==
    

    As you can see, environment variables are stored as data - i.e., base64-encoded strings, so you’ll need to encode the value of each variable. For example, To have HA_CONNECTION_TIMEOUT variable equal to 1000, you can run echo -n "1000" | base64 --wrap=0 (or just echo -n "1000" | base64 in case of Apple macOS) in your local shell and get MTAwMA==.

    Note

    Similarly, you can read the list of options from a Base64-encoded string:

    $ echo "MTAwMA==" | base64 --decode
    

    When ready, apply the YAML file with the following command:

    $ kubectl create -f deploy/my-env-secret.yaml
    

    Put the name of this Secret to the envVarsSecret key either in pxc, haproxy or proxysql section of the deploy/cr.yaml` configuration file:

    haproxy:
      ....
      envVarsSecret: my-env-var-secrets
      ....
    

    Now apply the deploy/cr.yaml file with the following command:

    $ kubectl apply -f deploy/cr.yaml
    

    Another example shows how to pass LD_PRELOAD environment variable with the alternative memory allocator library name to mysqld. It’s often a recommended practice to try using an alternative allocator library for mysqld in case the memory usage is suspected to be higher than expected, and you can use jemalloc allocator already present in Percona XtraDB Cluster Pods with the following environment variable:

    LD_PRELOAD=/usr/lib64/libjemalloc.so.1
    

    Create a new YAML file with the contents similar to the previous example, but with LD_PRELOAD variable, stored as base64-encoded strings:

    apiVersion: v1
    kind: Secret
    metadata:
      name: my-new-env-var-secrets
    type: Opaque
    data:
      LD_PRELOAD: L3Vzci9saWI2NC9saWJqZW1hbGxvYy5zby4x
    

    If this YAML file was named deploy/my-new-env-var-secret, the command to apply it will be the following one:

    $ kubectl create -f deploy/my-new-env-secret.yaml
    

    Now put the name of this new Secret to the envVarsSecret key in pxc section of the deploy/cr.yaml` configuration file:

    pxc:
      ....
      envVarsSecret: my-new-env-var-secrets
      ....
    

    Don’t forget to apply the deploy/cr.yaml file, as usual:

    $ kubectl apply -f deploy/cr.yaml
    

    Contact Us

    For free technical help, visit the Percona Community Forum.

    To report bugs or submit feature requests, open a JIRA ticket.

    For paid support and managed or consulting services , contact Percona Sales.


    Last update: 2023-02-09
    Back to top
    Percona LLC and/or its affiliates, © 2009 - 2022
    Made with Material for MkDocs

    Cookie consent

    We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.