Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Managing Kubernetes Resources Using Helm

You're reading from   Managing Kubernetes Resources Using Helm Simplifying how to build, package, and distribute applications for Kubernetes

Arrow left icon
Product type Paperback
Published in Sep 2022
Publisher Packt
ISBN-13 9781803242897
Length 310 pages
Edition 2nd Edition
Tools
Arrow right icon
Authors (2):
Arrow left icon
Andrew Block Andrew Block
Author Profile Icon Andrew Block
Andrew Block
Austin Dewey Austin Dewey
Author Profile Icon Austin Dewey
Austin Dewey
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Part 1: Introduction and Setup
2. Chapter 1: Understanding Kubernetes and Helm FREE CHAPTER 3. Chapter 2: Preparing a Kubernetes and Helm Environment 4. Chapter 3: Installing Your First App with Helm 5. Part 2: Helm Chart Development
6. Chapter 4: Scaffolding a New Helm Chart 7. Chapter 5: Helm Dependency Management 8. Chapter 6: Understanding Helm Templates 9. Chapter 7: Helm Lifecycle Hooks 10. Chapter 8: Publishing to a Helm Chart Repository 11. Chapter 9: Testing Helm Charts 12. Part 3: Advanced Deployment Patterns
13. Chapter 10: Automating Helm with CD and GitOps 14. Chapter 11: Using Helm with the Operator Framework 15. Chapter 12: Helm Security Considerations 16. Index 17. Other Books You May Enjoy

Setting up kubectl

As we mentioned in Chapter 1, Understanding Kubernetes and Helm, Kubernetes is a system that exposes different API endpoints. These API endpoints are used to perform various actions on a cluster, such as creating, viewing, or deleting resources. To provide a simpler user experience, developers need a way of interacting with Kubernetes without having to manage the underlying API layer.

While you will predominantly use the Helm command-line tool throughout this book to install and manage applications, kubectl is an essential tool for common tasks.

Read on to learn how to install kubectl on a local workstation. Note that the kubectl version that was used at the time of writing was v1.21.2.

Installing kubectl

kubectl can be installed using minikube, or it can be obtained via a package manager or through direct download. First, let’s describe how to obtain kubectl using minikube.

Installing kubectl via minikube

Installing kubectl is straightforward with minikube. minikube provides a subcommand called kubectl, which downloads the kubectl binary for you. Begin by running a kubectl command using minikube kubectl:

minikube kubectl version

This command installs kubectl to the $HOME/.minikube/cache/linux/v1.21.2 directory. Note that the version of kubectl that’s included in the path will depend on the version of minikube that is being used. To access kubectl once it has been installed, use the following syntax:

minikube kubectl -- <subcommand> <flags>

Here’s an example command:

$ minikube kubectl -- version --client
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2", GitCommit:"092fbfbf53427de67cac1e9fa54aaa09a28371d7", GitTreeState:"clean", BuildDate:"2021-06-16T12:59:11Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}

While invoking kubectl with minikube kubectl works, the syntax is more unwieldy than that of invoking kubectl directly. This can be overcome by copying the kubectl executable from the local minikube cache into a location that’s managed by the PATH variable. Performing this action is similar on each operating system, but the following is an example of how it can be achieved on a Linux machine:

$ sudo cp ~/.minikube/cache/linux/v1.21.2/kubectl /usr/local/bin/

Once complete, kubectl can be invoked as a standalone binary, as illustrated here:

$ kubectl version –client
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2", GitCommit:"092fbfbf53427de67cac1e9fa54aaa09a28371d7", GitTreeState:"clean", BuildDate:"2021-06-16T12:59:11Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}

kubectl can also be installed without minikube, as we’ll see in the following sections.

Installing kubectl without minikube

The Kubernetes upstream documentation provides several different mechanisms to do so for a variety of target operating systems, as described in https://kubernetes.io/docs/tasks/tools/install-kubectl/.

Using a package manager

Another way that kubectl can be installed without minikube is with a native package manager. The following list demonstrates how this can be accomplished on different operating systems:

  • Use the following command to install kubectl on Windows:
    choco install kubernetes-cli
  • Use the following command to install kubectl on macOS:
    brew install kubernetes-cli
  • Use the following command to install kubectl on Debian-based Linux:
    sudo apt-get update
    sudo apt-get install -y apt-transport-https ca-certificates curl
    sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
    echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
    sudo apt-get update
    sudo apt-get install -y kubectl
  • Use the following command to install kubectl on RPM-based Linux:
    cat <<EOF > /etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetesbaseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64enabled=1gpgcheck=1repo_gpgcheck=1gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpgEOF
    yum install -y kubectl

We will discuss the final kubectl installation method next.

Downloading directly from a link

kubectl can also be downloaded directly from a download link. The following list explains how version v1.21.2 can be downloaded, which is the version of kubectl that will be used throughout this book:

  • Download kubectl for Windows from https://storage.googleapis.com/kubernetes-release/release/v1.21.2/bin/windows/amd64/kubectl.exe.
  • Download kubectl for macOS from https://storage.googleapis.com/kubernetes-release/release/v1.21.2/bin/darwin/amd64/kubectl.
  • Download kubectl for Linux from https://storage.googleapis.com/kubernetes-release/release/v1.21.2/bin/linux/amd64/kubectl.

The kubectl binary can then be moved to a location that’s managed by the PATH variable. On the macOS and Linux operating systems, be sure to grant the file executable permission:

chmod u+x kubectl

The installation can be verified by running the following command.

$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2", GitCommit:"092fbfbf53427de67cac1e9fa54aaa09a28371d7", GitTreeState:"clean", BuildDate:"2021-06-16T12:59:11Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}

Now that we’ve covered how to set up kubectl, we’re ready to get into the key technology of this book – Helm.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image