This page looks best with JavaScript enabled

Learning Kubernetes with MiniKube on Windows 7

 ·  ☕ 5 min read

1. Basic Concepts

1.1 Kubernetes

Kubernetes (K8s for short), the successor to Google’s Borg, is an open-source system for automatically deploying, scaling, and managing containerized applications.

The features it provides:

  • Automated deployment of containers
  • Automated scaling up and down
  • Automated application/service upgrades
  • Grouping containers to serve traffic externally, with load balancing support
  • Health checks for services, with automatic restarts

1.2 Kubernetes Cluster

As shown above, a Kubernetes cluster contains two types of resources:

  • Master nodes, which coordinate and control the whole cluster

The Master is responsible for managing the cluster. It coordinates all behavior and activity in the cluster, such as running, modifying, and updating applications.

  • Node nodes, the worker nodes that run applications.

A Node is a worker node in the Kubernetes cluster and can be a VM or a physical machine. Every Node has a Kubelet, which manages communication between the node and the Kubernetes Master.

1.3 Kubelet

The main job of the Kubelet is to periodically fetch the desired state of the Pods/Containers on its node — which containers to run, how many replicas, how networking or storage should be configured, and so on — from a local source or from the API, and to call the corresponding container platform interfaces to reach that state. The main capabilities the Kubelet provides:

  • Pod management
  • Container health checks
  • Container monitoring

1.4 MiniKube

During development you can use Minikube to get a lightweight Kubernetes cluster by creating a local virtual machine and deploying a simple single-node cluster on it.

The Minikube CLI provides the basic cluster operations, including start, stop, status, and delete.

2. Installation

2.1 Requirements

  • kubectl, for managing Node nodes
  • Windows
    • VirtualBox or Hyper-V, the underlying virtual machine
  • VT-x/AMD-v virtualization must be enabled in BIOS, i.e. the virtualization instruction set must be turned on
  • Internet connection on first run, an internet connection is required on the first run

Since Docker Toolbox for Windows was installed previously, VirtualBox is already installed. Here I will mainly cover how to install kubectl and MiniKube.

2.2 Installing Kubectl

The official documentation describes in detail how to install kubectl on various systems. On Windows, use the Chocolatey package manager (for the install method, see an earlier post):

1
2
3
4
5
6
choco install kubernetes-cli
Chocolatey v0.10.11
Installing the following packages:
kubernetes-cli
By installing you accept licenses for the packages.
Progress: Downloading kubernetes-cli 1.11.3... 100%
1
2
3
kubectl version
Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.3", GitCommit:"a4529464e4629c21224b3d52edfe0ea91b072862", GitTreeState:"clean", BuildDate:"2018-09-09T18:02:47Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"windows/amd64"}
Unable to connect to the server: dial tcp 127.0.0.1:8080: connectex: No connection could be made because the target machine actively refused it.

Because the service has not been started, it reports that it cannot connect.

2.3 Installing MiniKube

In MiniKube’s GitHub repository, how to install MiniKube on various systems is described in detail. MiniKube is written in Go. On Windows you can download the MiniKube executable and install it directly, or you can install it with the Chocolatey package manager.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
choco install minikube
Chocolatey v0.10.11
Installing the following packages:
minikube
By installing you accept licenses for the packages.
Progress: Downloading Minikube 0.28.2... 100%

Minikube v0.28.2 [Approved]
minikube package files install completed. Performing other installation steps.
 ShimGen has successfully created a shim for minikube.exe
 The install of minikube was successful.
  Software install location not explicitly set, could be in package or
  default install location if installer.

3. Usage

3.1 Creating and Starting a Cluster

Using the minikube start command, you can create and configure a virtual machine running a single-node Kubernetes cluster, and at the same time configure kubectl to communicate with this cluster.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
minikube start
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Downloading Minikube ISO
 160.27 MB / 160.27 MB  100.00% 0ssss
Getting VM IP address...
Moving files into cluster...
Downloading kubelet v1.10.0
Downloading kubeadm v1.10.0
Finished Downloading kubelet v1.10.0
Finished Downloading kubeadm v1.10.0
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components

Minikube uses VirtualBox as the driver by default; the --vm-driver flag lets you specify a driver. Setting the MINIKUBE_HOME environment variable lets you specify the installation directory; the default installation directory is C:\Users\Your User Name\.minikube.

Check whether the node is healthy:

1
2
3
kubectl get nodes
NAME       STATUS    ROLES     AGE       VERSION
minikube   Ready     master    1d        v1.10.0

3.2 Pulling Images

If the network is restricted, the gcr.io page cannot be opened. There are two ways to solve the problem of images failing to pull. Given my environment, I can access the internet through a proxy, so here I only offer the general approach.

  • First, configure a proxy
1
minikube start --docker-env HTTP_PROXY=127.0.0.1:1234

Finding a usable proxy is not an easy task, so you can try the second approach.

  • Second, pull from the Alibaba Cloud mirror and retag
1
2
3
minikube ssh
docker pull registry.cn-beijing.aliyuncs.com/google-containers/kube-addon-manager-amd64:v6.1
docker tag registry.cn-beijing.aliyuncs.com/google-containers/kube-addon-manager-amd64:v6.1 gcr.io/google-containers/kube-addon-manager:v6.1

3.3 Starting a Service

Create an Nginx Pod service

1
2
kubectl run kube-nginx --image=nginx:latest --port=80
deployment.apps/kube-nginx created

Expose the service through NodePort

1
2
kubectl expose deployment kube-nginx --type=NodePort
service/kube-nginx exposed

Check the Pod status

1
2
3
kubectl get pods
NAME                             READY     STATUS              RESTARTS   AGE
kube-nginx-6d8f6d45-rwz2g        1/1       Running             0          1d

Get the URL for accessing Nginx

1
2
minikube service kube-nginx --url
http://192.168.99.100:30832

Open the page

3.4 MiniKube Basic Commands

  • Start the cluster
1
minikube start
  • Check the status
1
2
3
4
minikube status
minikube: Running
cluster: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100
  • View the logs
1
minikube logs
  • Stop the cluster
1
2
3
minikube stop
Stopping local Kubernetes cluster...
Stopping "minikube"...
  • Delete the cluster
1
minikube delete
  • Check the IP
1
2
minikube ip
192.168.99.100

3.5 Viewing the Dashboard

1
2
minikube dashboard
Opening kubernetes dashboard in default browser...

4. References


微信公众号
WRITTEN BY
微信公众号