Install Consul on Kubernetes from Consul K8s CLI

This topic describes how to install Consul on Kubernetes using the Consul K8s CLI tool. The Consul K8s CLI tool enables you to quickly install and interact with Consul on Kubernetes. Use the Consul K8s CLI tool to install Consul on Kubernetes if you are deploying a single cluster. We recommend using the Helm chart installation method if you are installing Consul on Kubernetes for multi-cluster deployments that involve cross-partition or cross datacenter communication.

Introduction

If it is your first time installing Consul on Kubernetes, then you must first install the Consul K8s CLI tool. You can install Consul on Kubernetes using the Consul K8s tool after installing the CLI.

Requirements

  • The kubectl client must already be configured to authenticate to the Kubernetes cluster using a valid kubeconfig file.
  • Install one of the following package managers so that you can install the Consul K8s CLI tool. The installation instructions also provide commands for installing and using the package managers:
    • MacOS: Homebrew
    • Ubuntu/Debian: apt
    • CentOS/RHEL: yum

You must install the correct version of the CLI for your Consul on Kubernetes deployment. To deploy a previous version of Consul on Kubernetes, download the specific version of the CLI that matches the version of the control plane that you would like to deploy. Refer to the compatibility matrix for details.

Install the CLI

The following instructions describe how to install the latest version of the Consul K8s CLI tool, as well as earlier versions, so that you can install an appropriate version of tool for your control plane.

Install the latest version

Complete the following instructions for a fresh installation of Consul on Kubernetes.

The Homebrew package manager is required to complete the following installation instructions. The Homebrew formulae always installs the latest version of a binary.

  1. Install the HashiCorp tap, which is a repository of all Homebrew packages for HashiCorp:

    1. $ brew tap hashicorp/tap
  2. Install the Consul K8s CLI with hashicorp/tap/consul formula.

    1. $ brew install hashicorp/tap/consul-k8s
  3. (Optional) Issue the consul-k8s version command to verify the installation:

    1. $ consul-k8s version
    2. consul-k8s 1.0
  4. Add the HashiCorp GPG key.

    1. $ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
  5. Add the HashiCorp apt repository.

    1. $ sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
  6. Run apt-get install to install the consul-k8s CLI.

    1. $ sudo apt-get update && sudo apt-get install consul-k8s
  7. (Optional) Issue the consul-k8s version command to verify the installation.

    1. $ consul-k8s version
    2. consul-k8s 1.0
  8. Install yum-config-manager to manage your repositories.

    1. $ sudo yum install -y yum-utils
  9. Use yum-config-manager to add the official HashiCorp Linux repository.

    1. $ sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
  10. Install the consul-k8s CLI.

    1. $ sudo yum -y install consul-k8s
  11. (Optional) Issue the consul-k8s version command to verify the installation.

    1. $ consul-k8s version
    2. consul-k8s 1.0

Install a previous version

Complete the following instructions to install a specific version of the CLI so that your tool is compatible with your Consul on Kubernetes control plane. Refer to the compatibility matrix for additional information.

  1. Download the appropriate version of Consul K8s CLI using the following curl command. Set the $VERSION environment variable to the appropriate version for your deployment.

    1. $ export VERSION=1.1.1 && \
    2. curl --location "https://releases.hashicorp.com/consul-k8s/${VERSION}/consul-k8s_${VERSION}_darwin_amd64.zip" --output consul-k8s-cli.zip
  2. Unzip the zip file output to extract the consul-k8s CLI binary. This overwrites existing files and also creates a .consul-k8s subdirectory in your $HOME folder.

    1. $ unzip -o consul-k8s-cli.zip -d ~/consul-k8s
  3. Add the path to your directory. In order to persist the $PATH across sessions, dd it to your shellrc (i.e. shell run commands) file for the shell used by your terminal.

    1. $ export PATH=$PATH:$HOME/consul-k8s
  4. (Optional) Issue the consul-k8s version command to verify the installation.

    1. $ consul-k8s version
    2. consul-k8s 1.0
  5. Add the HashiCorp GPG key.

    1. $ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
  6. Add the HashiCorp apt repository.

    1. $ sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
  7. Run apt-get install to install the consul-k8s CLI.

    1. $ export VERSION=0.39.0 && \
    2. sudo apt-get update && sudo apt-get install consul-k8s=${VERSION}
  8. (Optional) Issue the consul-k8s version command to verify the installation.

    1. $ consul-k8s version
    2. consul-k8s 1.0
  9. Install yum-config-manager to manage your repositories.

    1. $ sudo yum install -y yum-utils
  10. Use yum-config-manager to add the official HashiCorp Linux repository.

    1. $ sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
  11. Install the consul-k8s CLI.

    1. $ export VERSION=-1.0 && \
    2. sudo yum -y install consul-k8s-${VERSION}-1
  12. (Optional) Issue the consul-k8s version command to verify the installation.

    1. $ consul-k8s version
    2. consul-k8s 1.0

Install Consul on Kubernetes

After installing the Consul K8s CLI tool (consul-k8s), issue the install subcommand and any additional options to install Consul on your existing Kubernetes cluster. Refer to the Consul K8s CLI reference for details about all commands and available options. If you do not include any additional options, the consul-k8s CLI installs Consul on Kubernetes using the default settings form the Consul Helm chart values. The following example installs Consul on Kubernetes with service mesh and CRDs enabled.

  1. $ consul-k8s install
  2. ==> Pre-Install Checks
  3. No existing installations found.
  4. No previous persistent volume claims found
  5. No previous secrets found
  6. ==> Consul Installation Summary
  7. Installation name: consul
  8. Namespace: consul
  9. Overrides:
  10. connectInject:
  11. enabled: true
  12. Proceed with installation? (y/N) y
  13. ==> Running Installation
  14. Downloaded charts
  15. --> creating 1 resource(s)
  16. --> creating 45 resource(s)
  17. --> beginning wait for 45 resources with timeout of 10m0s
  18. Consul installed into namespace "consul"

You can include the -auto-approve option set to true to proceed with the installation if the pre-install checks pass.

The pre-install checks may fail if existing PersistentVolumeClaims (PVC) are detected. Refer to the uninstall instructions for information about removing PVCs.

Check the Consul cluster status

Issue the consul-k8s status command to view the status of the installed Consul cluster.

  1. $ consul-k8s status
  2. ==> Consul-K8s Status Summary
  3. NAME | NAMESPACE | STATUS | CHARTVERSION | APPVERSION | REVISION | LAST UPDATED
  4. ---------+-----------+----------+--------------+------------+----------+--------------------------
  5. consul | consul | deployed | 0.40.0 | 1.14.0 | 1 | 2022/01/31 16:58:51 PST
  6. Consul servers healthy (3/3)
  7. Consul clients healthy (3/3)