00 Pre Lesson Preparation Practicing Is the Best Way to Learn

00 Pre-Lesson Preparation Practicing is the Best Way to Learn #

Hello, I’m Chrono. Today, our task is to set up the experimental environment.

If you have read my other two Geek Time columns (“Perspective on the HTTP Protocol” and “C++ Practical Notes”), you will know that I have always emphasized the importance of the experimental environment. After all, the practicality of computer science is greater than its theoretical aspect. Having a practical environment that can be operated is also very helpful for learning theory.

In our Kubernetes learning class, the experimental environment is even more essential. Unlike network protocols and programming languages, Kubernetes is a massive system that is more closely related to production environments. If we only focus on theory without practice, even if you grasp a lot of knowledge, it will only be “idle talk” without real-world application.

As the saying goes, “A craftsman must sharpen his tools first.” Therefore, before we start formal learning, we must have a basic experimental environment. This environment should allow us to become familiar with Kubernetes’ commands, validate and test various features of Kubernetes. With such assistance, our learning will be much more efficient.

Choosing the Right Experimental Environment #

However, it is not easy to obtain a complete Kubernetes environment because it is complex and requires high software and hardware specifications. There are also many small details in the installation and deployment process that can become obstacles during the learning process.

So, how should we build an experimental environment that meets our requirements?

You may say: there are many cloud vendors available online, so just apply for one.

This may be a convenient way to obtain a Kubernetes environment, but I have a different opinion.

Firstly, these online “cloud servers” are rarely free and require payment. Moreover, if you want a good configuration, you need to spend even more money, which is not cost-effective for our learning purposes. Secondly, “cloud servers” are on the “cloud” and are inevitably subject to network and vendor restrictions, which introduce instability. Lastly, these “cloud servers” are already pre-configured by the vendor and have fixed software and hardware, making it difficult to customize them, especially if we want to build them from scratch.

Considering these three points, I recommend building the experimental environment locally. This way, we won’t be restricted by others and have complete autonomy and control.

However, Kubernetes usually runs in a cluster environment composed of multiple servers. Do we really need to purchase multiple computers to build a network?

That’s not necessary. Because virtual machine software is now mature and reliable, we can virtualize multiple hosts on a single computer. These virtual hosts are almost indistinguishable from real physical hosts, as long as your computer configuration is not too poor. It is completely feasible to create a small cluster of three or four virtual servers, and the creation and deletion of virtual machines are straightforward with very low cost.

Using virtual machine software also has an additional benefit. Because many cloud service providers also use virtual servers extensively, the container technology in Kubernetes has many similarities with virtual machines. By using virtual machines, we can also compare the similarities and differences between these technologies, deepening our understanding of Kubernetes.

Therefore, considering these factors, I suggest selecting a laptop or desktop computer with decent specifications and using virtual machines to build our experimental environment for this course.

The CPU and hard disk requirements for the host computer are not high, 4 cores and 300GB are sufficient. The key is to have enough memory because virtual machines and Kubernetes both require a significant amount of memory. At least 8GB of memory is necessary to support a minimum cluster consisting of two virtual machines.

Choosing a Virtual Machine Software #

Once we have determined the general direction of our experimental environment - virtual machines, we need to choose virtual machine software.

There are only a few mainstream virtual machine software available on the market, so the choice is not difficult. I personally recommend two: VirtualBox and VMWare Fusion.

Let’s start with VirtualBox, which has a wide range of applications.

VirtualBox is a virtual machine software developed by Oracle. It has a long history and has always adhered to a free policy. There are no restrictions on its terms of use, making it a rare high-quality software.

VirtualBox supports Windows and macOS, but it has a small drawback. It can only run on Intel (x86_64) chips and does not support Apple’s new M1 (arm64/aarch64) chips. This means that it cannot be used on the latest Mac models, which is a big regret.

Therefore, if you have an Apple M1 Mac, you can only choose other virtual machine software. For macOS, the most famous virtual machine software should be Parallel Desktop and VMWare Fusion, both of which require payment. Here, I highly recommend VMWare Fusion.

However, in terms of VMWare Fusion, its support for M1 has been progressing slowly. Therefore, before the official paid version is released, a “Tech Preview” was announced, which is completely free and has good functionality and performance. Although it has a time limit (about 300 days), it is sufficient for our learning purposes.

Here are the links for VirtualBox (https://www.virtualbox.org/wiki/Downloads) and VMWare Fusion (https://communities.vmware.com/t5/Fusion-for-Apple-Silicon-Tech/ct-p/3022). You can take a look and download them as soon as possible.

Choosing a Linux Distribution #

Once we have virtual machine software, we need to install an operating system on it. When it comes to this, Linux is the obvious choice because Kubernetes can only run on Linux.

However, the Linux world is divided into many different distributions, with popular ones such as CentOS/Fedora, Ubuntu/Debian, SUSE, and so on. There is no single system that dominates completely.

Image

So, which one is better to choose?

Our main purpose is to learn, so usability should be the primary concern. Additionally, the system should support both x86_64 and arm64. After filtering, I recommend choosing the Ubuntu 22.04 Jammy Jellyfish Desktop Edition (https://ubuntu.com/download/desktop). It has sufficiently new features and is very suitable for running Kubernetes. The built-in browser, terminal, and other tools are also convenient for debugging and testing.

However, there is some bad news for Apple M1 users. When Ubuntu 22.04 upgraded its kernel from 5.13 to 5.15, a small bug was introduced that prevents VMWare Fusion from being installed and started properly. This issue has not been resolved as of the official release in April.

Fortunately, for testing purposes, I downloaded an earlier “daily build” version that can be installed normally in VMWare Fusion. I have uploaded it to the cloud drive (https://www.aliyundrive.com/s/FRmnawAURKu) for you to download and use.

One thing to note is that due to website restrictions, the file extension has been changed to .mov. You must remove this extension and restore it to the original .iso in order to use it.

How to Configure a Virtual Machine #

After preparing the virtual machine software and the Ubuntu disc image, we can proceed with installing the virtual machine. However, before installation, we must configure the virtual machine appropriately.

Because Kubernetes is not just a regular application software, but a complex system software, it has slightly higher hardware requirements. Fortunately, the requirements are not too high. The minimum requirements are a 2-core CPU and 2GB RAM. If conditions allow, I recommend increasing the RAM to 4GB and the hard disk to 40GB or more. This will ensure smoother operation. Additionally, unnecessary devices for a server, such as sound cards, webcams, floppy drives, etc., can be disabled or removed to save some system resources.

Image

Since Linux servers are mainly accessed via terminal login and require networking for multiple servers, we need to make some special network settings.

As mentioned earlier, VirtualBox is the preferred virtual machine software, and VMWare Fusion Technology Preview is an alternative for Apple M1 Mac. Let me explain how to configure these two software options separately.

For VirtualBox, first, you need to create a “Host-only” network under “Tools - Network.” The IP address range can be arbitrary. For example, here we will use the automatically assigned range “192.168.56.1/24”:

Image

Next, in the virtual machine configuration, you need to enable two network adapters. Set “Adapter 1” to the previously created “Host-only” network, which we will use for local terminal access and networking. “Adapter 2” should be set to “NAT (Network Address Translation)” for external Internet access:

Image

For VMWare Fusion, you need to add a custom network under “Preferences - Network,” such as “vmnet3,” with a network segment of “192.168.10.0.” Allow NAT for connecting to the Internet. Then, in the virtual machine network settings, select this network:

Image

Image

How to Install a Virtual Machine #

After configuring the CPU, memory, hard drive, and network, you can load the Ubuntu 22.04 disc image to start the Linux installation.

During the installation process, to save time, it is recommended to choose “Minimal Installation” and physically disconnect from the network to avoid downloading upgrade packages. Note that disconnecting from the network is especially important for Apple M1, otherwise Ubuntu will automatically update to kernel 5.15, which will prevent normal startup after installation.

After installing the Linux system, we need to perform some environment initialization operations.

First, open a command line window by pressing Ctrl + Alt + T, and then use apt to install common tools such as git, vim, curl from Ubuntu’s official software repository:

sudo apt update
sudo apt install -y git vim curl jq

The Ubuntu Desktop version does not support remote login by default. Therefore, in order to facilitate subsequent experiments, we need to install “openssh-server” and then use the ip addr command to check the IP address of the virtual machine. Then, you can use the ssh command on the host machine to log in to the virtual machine:

sudo apt install -y openssh-server
ip addr

Image

From this screenshot, we can see that this VirtualBox virtual machine has three network cards, and the network card named “enp0s3” is the one we configured earlier in the “192.168.56.1/24” network segment, with an automatically assigned IP address of “192.168.56.11”.

If you are not satisfied with the automatically assigned IP address, you can also modify the network card in the system settings in the upper right corner of Ubuntu. Change it from dynamic address (DHCP) to static address (Manual). The specific parameters can be referred to the following screenshot. After restarting, the new IP address will take effect.

Image

Image

After completing these tasks, I recommend that you take a snapshot of the virtual machine as a backup. This way, if there are any unexpected issues later that mess up the environment, you can easily roll back to the correct state when the snapshot was taken.

Image

Now, let’s start a command line terminal (I’m using “iTerm2” on a Mac), use ssh, enter the username, password, and IP address, and you will be able to log in to the created virtual machine:

Image

Common Linux Operations #

With that, our experimental environment is set up. Although we currently only have the basic Linux system, we will gradually improve and create a complete Kubernetes environment in the “Getting Started,” “Intermediate,” and “Advanced” sections.

A special reminder is that Kubernetes is based on Linux. Although there is also a graphical dashboard, most of the work is done in the command line. Therefore, it is necessary for you to have a basic understanding of Linux operations.

Learning the Linux operating system is a separate and extensive topic. Although it is important, it is not the focus of this course. Here are some commonly used knowledge points. You can test your understanding and if there is anything you are not familiar with, I hope you can search for relevant information after the class to supplement these points:

  • The command line interface is called the “Shell,” which supports both interactive and script operations, known as “Shell scripting.”
  • The root user has the highest privilege but poses security risks. Therefore, we usually only use ordinary user accounts and use sudo when necessary to temporarily gain root privileges.
  • The command to view the current process list in the system is ps, which is one of the most commonly used commands in Linux.
  • The cat command can be used to view files. If the content is too long, you can use the pipe symbol | followed by more or less.
  • Vim is the most popular editor in Linux, but its usage is different from general editors and has a slightly higher learning curve.
  • Curl can send HTTP requests in a command line manner and is commonly used to test HTTP servers (such as Nginx).

Summary #

Alright, our pre-class preparation is coming to an end, and I’ll briefly summarize today’s key points:

  1. A well-equipped lab environment can greatly assist our learning. It is recommended to build a Kubernetes environment from scratch using a virtual machine locally.
  2. Virtual machine software options include VirtualBox (Intel chipset) and VMWare Fusion (Apple M1 chipset). Since Kubernetes can only run on Linux, it is advisable to choose the latest Ubuntu 22.04.
  3. The virtual machine should be configured with parameters such as memory and network in advance. During system installation, select the minimal installation option, and then install some commonly used tools.
  4. Virtual machines support snapshots. After setting up the environment, it is important to backup regularly. In case of any issues, you can easily roll back and restore, avoiding wasted time on repetitive system installations.

Image

Throughout today’s setup process, the virtual machine configuration is crucial. I have also recorded a video specifically for you to reference and compare for a clearer understanding:-

Additionally, as per my column’s tradition, I have created a corresponding learning project on GitHub. The repository for this course is called “k8s_study” (https://github.com/chronolaw/k8s_study). It contains document links, installation scripts, test commands, YAML description files, and more. You can clone it and refer to it for future lessons.

Homework #

Finally, it’s time for homework. Please take practical action and set up a Linux experimental environment using a virtual machine on your own computer, in preparation for the formal study of Docker in the next class.

Feel free to participate in the discussion below with other classmates. If you have any questions during the setup process, please leave a comment, and I will reply to you as soon as possible.-