With the popularity of cloud-native technologies such as containerization, microservices, service mesh, service orchestration, and DevOps, we need to keep up with the times. So how do we get on board? At this point, we need a tool that is easy to run locally and works with Kubernetes, allowing us to easily create a standalone Kubernetes cluster in a virtual machine on your laptop, facilitating our daily development and learning with Kubernetes. Now, let's easily set up a more realistic K8s environment.
Tool Recommendations#
For local experimentation, various Kubernetes implementations can be used to run Kubernetes clusters, such as:
- Kind (https://kind.sigs.k8s.io/)
- Minikube (https://minikube.sigs.k8s.io/docs/)
- MicroK8s (https://microk8s.io/)
- Online K8s Experience (https://labs.play-with-k8s.com/)
- Dockerized (https://github.com/y0ngb1n/dockerized) Recommended my personal project, welcome to Star
The goal of using any of the above tools is to quickly run a local learning Kubernetes cluster, among which my personal favorite is Kind.
Setting Up K8s Cluster#
Next, let's try creating a standalone Kubernetes cluster with Kind and Minikube.
First, Install kubectl#
Regardless of which tool you use, you need to correctly install the kubectl Kubernetes command-line tool first; otherwise, you won't be able to execute kubectl commands after installing Kind, Minikube, and other environments.
- Installation Documentation: https://kubernetes.io/zh/docs/tasks/tools/#kubectl
Create K8s Cluster Using Kind#
kind is a tool for running local Kubernetes clusters using Docker container “nodes”.
Install kind#
Kind provides various installation methods, supporting the following:
- On macOS via Homebrew
- On macOS via MacPorts
- On Windows via Chocolatey
- Installing From Release Binaries
- Installing From Source
Here, we will install it in a Linux environment using the Installing From Release Binaries method:
Create K8s Cluster#
Verify Installation Environment#
Create K8s Cluster Using Minikube#
Install minikube#
Choose the installation method for different environments, refer to https://minikube.sigs.k8s.io/docs/start/
In a domestic network environment, use the following command to automatically use Alibaba Cloud services to support the minikube environment configuration, refer to https://developer.aliyun.com/article/221687
Verify Installation Environment#
Start the K8s dashboard, refer to https://minikube.sigs.k8s.io/docs/handbook/dashboard/
View the list of extensions supported by minikube, refer to https://minikube.sigs.k8s.io/docs/handbook/deploying/
Verify K8s Cluster#
First Experience with K8s#
Quick Taste#
A Small Trial#
nginx-pod.yml
nginx-svc.yml
Execute the command:
Notes#
- You need to correctly install
kubectlfirst - Port-Forward allows local access to Pod, limited to local debugging environments, such as
curl 127.0.0.1:8080 - When using Service for reverse proxy, you need to access using the K8s cluster's IP, use
kubectl get nodes -o wideto view the K8s cluster's IP - Service is a mechanism provided by K8s for reverse proxy, responsible for reverse routing + load balancing
- NodePort is a type of Service that can expose the Service to the external network
- NodePort range is
30000~32767 - Label is K8s's labeling mechanism
- Selector is the routing selection mechanism in K8s
- K8s clusters deployed using Kind or Minikube run nodes based on containers rather than the host machine; when using Service for reverse proxy, kube-proxy only takes effect in the node container, verify this by using
docker exec -it kind-control-plane bash, not directly mapped on the host machine