Feedback

Chat Icon

Cloud-Native Microservices With Kubernetes - 2nd Edition

A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in Kubernetes

Setting Up the Foundation
10%

Installing the Necessary Tools

kubectl is the command-line tool for interacting with Kubernetes clusters. Think of it as the aws CLI for AWS or the gcloud CLI for Google Cloud, but specifically for Kubernetes.

Before diving into Kubernetes, we need to install kubectl on our workspace server. Start by SSHing into the server if you haven't already:

ssh -i $DIGITALOCEAN_SSH_PRIVATE_KEY_PATH root@$WORKSPACE_IP

Now, let's install kubectl:

# Download the latest stable release of kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

# Install kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

# Test to ensure the version you installed is up-to-date
kubectl version --client --output=yaml

# Clean up the downloaded file
rm kubectl

# Create an alias for kubectl
echo 'alias k=kubectl' >> ~/.bashrc

# Activate kubectl autocompletion
kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl > /dev/null
sudo chmod a+r /etc/bash_completion.d/kubectl

# Source the completion in the current session
source /etc/bash_completion.d/kubectl

# Now set up completion for the k alias
echo 'complete -o default -F __start_kubectl k' >> ~/.bashrc
complete -o default -F __start_kubectl k

# Source the bashrc file to load the new configurations
source ~/.bashrc

To understand how Kubernetes helps us manage and deploy microservices, we will need to create real applications. We will use Python as a programming language. The choice of Python is based on its simplicity and ease of use. Even if you are not a Python developer, you will be able to follow along without any issues. Other programming languages can be more challenging to understand if you are not familiar with them. We need to install Python and some additional tools, including:

  • Python 3: The programming language we will use to create our applications.
  • pip3: The official package manager and pip command for Python 3.
  • virtualenvwrapper: A set of extensions for managing virtual development environments in Python.
# Install Python 3 if not already installed
apt update && apt install -y python3 python3-pip

# Verify Python 3 installation
python3 --version

# Install virtualenvwrapper if not already installed

Cloud-Native Microservices With Kubernetes - 2nd Edition

A Comprehensive Guide to Building, Scaling, Deploying, Observing, and Managing Highly-Available Microservices in Kubernetes

Enroll now to unlock all content and receive all future updates for free.