preface

The previous series of tutorials are in ali cloud practice, recently assembled their own desktop computer, installed on the Win10 system. In order to let more partners have the opportunity to learn k8S choreography, here uses another simpler scheme — Docker for Windows. Of course, you can also use Docker for MAC. Their installation and use are similar. Here focus on the installation of win10.

The preparatory work

The system configuration

Start virtualization

Check whether the CPU supports virtualization and whether virtualization is enabled.

If no, go to the BIOS to set the BIOS.

To enable the Hyper – V

The installation of Docker for Windows requires the use of virtualization, which can be hyper-V or Oracle Virtual Box. If the installed system does not meet the requirements of running Docker for Windows, Docker Toolbox can be installed. No introductions here.

Settings -> Applications -> Programs and Features -> Enable and Disable Windows features

To enable the Hyper – V

The NFS client will be enabled as required in the k8S tutorial. The Telnet client is also a common tool, which is also enabled incidentally.

When enabled, restart the computer.

Download address

Docker for Windows

website

Install the Docker

Double-click the Docker for Windows Installer.exe downloaded above

If the installation is successful, an icon is displayed on the desktop

Check the lower right foot

Can modify the image acceleration, here using Ali cloud.

As long as Docker running is green, Kubernetes don’t worry about it. If the installation fails, the installation will fail.

Verify the docker installation

  • Open terminal to view version:
docker version
Copy the code

  • Download the nginx image
docker pull nginx
Copy the code

  • Run the nginx image
docker run -p 81:80 -d --name mynginx nginx
Copy the code

Git bash is used to make it easier to use Linux commands

  • Browser accesshttp://localhost:81

  • Clean up the nginx instance you just ran
#Stop the instance named mynginx that you just ran
docker ps -a | grep mynginx | awk '{print $1}' | xargs docker stop
#Delete the running instance named mynginx
docker ps -a | grep mynginx | awk '{print $1}' | xargs docker rm
Copy the code

Install Kubernetes

Preparing an installation image

If you do not prepare the image in advance, when Kubernetes is enabled, the page will be stuck, the reason is that the image will be downloaded from the official address provided by Kubernetes by default, the address is blocked in China, so we need to download the relevant image to the local first.

Github.com/AliyunConta…

! [

] (qiniu.mldong.com/mldong-arti…).

  • Clone script
git clone https://github.com/AliyunContainerService/k8s-for-docker-desktop.git
Copy the code
  • Enter the directory
cd k8s-for-docker-desktop
Copy the code
  • Check out the corresponding version branch
Git checkbot v1.16.5Copy the code
  • Run PowerShell as an administrator

  • Re-enter the k8S-for-Docker-desktop directory
  • Example Set the script execution permission
Set-ExecutionPolicy RemoteSigned
Copy the code
  • Run the image download script

The logic of the script is that

  1. Download the image from ali Cloud mirror warehouse
  2. Example Change the mirror tag to the official address
  3. Delete Ali mirror
./load_images.ps1
Copy the code
  • The script execution permission is disabled
Set-ExecutionPolicy Restricted
Copy the code

Enable the Kubernetes cluster

With the image installed, you are ready to enable the Kubernetes cluster. This process will take a while, and Kubernetes will turn green after normal startup.

Download the Kubectl client

Download address: www.kubernetes.org.cn/installkube…

Configuring environment variables is omitted.

Verify the Kubernetes cluster

  • Switching the Current Cluster
kubectl config use-context docker-desktop
Copy the code
  • Verify Kubernetes cluster status
kubectl cluster-info
kubectl get nodes
Copy the code

Install the ingress – nginx

Those of you who have seen the previous series of articles probably know that Kubernetes exposes services in three ways.

  • LoadBlancer Service
  • NodePort Service
  • Ingress

Here do not do too much introduction, want to know the students can go to check information. When we use the cloud platform, the cloud platform has already installed ingress-nginx, we just need to define the YAML file to use, here we need to install ourselves.

Ingress-nginx load balancing call order: User >ingress-nginx(POD)– >ingress-nginx(controller)– >service– > POD

Different versions of Kubernetes use different versions of ingress-nginx.

Can see k8s – for – docker – desktop/images. The properties files

Github address: github.com/kubernetes/…

Whatever version it is, go to the corresponding file.

  • Download the YAML files in turn

  • Start the installation
kubectl apply -f mandatory.yaml
kubectl apply -f cloud-generic.yaml
Copy the code
  • To view
kubectl get pods -n ingress-nginx
Copy the code

  • Browser accesshttp://localhost

Publish a complete nginx service

Creating a namespace

  • nginx-ns.yaml
cat << EOF > nginx-ns.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: mldong-study
  
EOF

Copy the code
  • Execute issue command
kubectl apply -f nginx-ns.yaml
Copy the code
  • Viewing the Execution Result
kubectl get ns
Copy the code

Create the ConfigMap- configuration file

  • nginx-cm.yaml
cat << EOF > nginx-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-cm
  namespace: mldong-study
data:
  a.conf: |- server { listen 80; server_name a.study.com; location / { root /usr/share/nginx/html; index a.html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }}  b.conf: |- server { listen 80; server_name b.study.com; location / { root /usr/share/nginx/html; index b.html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }}    
  
EOF

Copy the code
  • Execute issue command
kubectl apply -f nginx-cm.yaml
Copy the code
  • Viewing the Execution Result
kubectl get cm -n mldong-study
Copy the code

Create the configmap-html file

It is not very convenient to use HostPath on Win. NFS will be used later. Here’s the simplest way to do it.

  • nginx-cm-html.yaml
cat << EOF > nginx-cm-html.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-cm-html
  namespace: mldong-study
data:
  a.html: |- aaaaaa  b.html: |- bbbbbb  
EOF

Copy the code
  • Execute issue command
kubectl apply -f nginx-cm-html.yaml
Copy the code
  • Viewing the Execution Result
kubectl get cm -n mldong-study
Copy the code

Create a Deployment

  • nginx-deployment.yaml
cat << EOF > nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: mldong-study
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      annotations:
        version/config: V0001
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
              name: port
              protocol: TCP
          volumeMounts:
            - name: nginx-cm-html
              mountPath: "/usr/share/nginx/html"
            - name: nginx-cm
              mountPath: "/etc/nginx/conf.d"ls
      volumes:
        - name: nginx-cm-html
          configMap: 
            name: nginx-cm-html
        - name: nginx-cm
          configMap:
            name: nginx-cm
  
EOF
Copy the code
  • Execute issue command
kubectl apply -f nginx-deployment.yaml
Copy the code
  • Viewing the Execution Result
kubectl get pods -n mldong-study
Copy the code

Create a Service

  • nginx-service.yaml
cat << EOF > nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-nodeport
  namespace: mldong-study
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    #nodePort: 32180
  selector:
    app: nginx
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  namespace: mldong-study
spec:
  type: ClusterIP
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx

EOF

Copy the code
  • Execute issue command
kubectl apply -f nginx-service.yaml
Copy the code
  • Viewing the Execution Result
kubectl get service -n mldong-study
Copy the code

Create the Ingress

  • nginx-ingress.yaml
cat << EOF > nginx-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
  name: mynginx-ingress
  namespace: mldong-study
spec:
  rules:
    - host: a.study.com
      http:
        paths:
          - backend:
              serviceName: nginx
              servicePort: 80
            path: /
    - host: b.study.com
      http:
        paths:
          - backend:
              serviceName: nginx
              servicePort: 80
            path: /

  
EOF

Copy the code
  • Execute issue command
kubectl apply -f nginx-ingress.yaml
Copy the code
  • Viewing the Execution Result
kubectl get ingress -n mldong-study
Copy the code

Modify the hosts

Browser access

a.study.com

b.study.com

Final cleanup

kubectl delete -f nginx-ns.yaml
Copy the code

To run the command again, run the following commands:

kubectl apply -f nginx-ns.yaml
kubectl apply -f nginx-cm.yaml
kubectl apply -f nginx-cm-html.yaml
kubectl apply -f nginx-deployment.yaml
kubectl apply -f nginx-service.yaml
kubectl apply -f nginx-ingress.yaml
Copy the code

summary

This article installs Docker for Windows on Win10 system, and enables its Kubernetes cluster – single node version, complete release of a nginx service. After installing Docker for Windows and successfully enabling Kubernetes, you are ready to learn k8S choreography, so to speak. Of course, in this environment, not only can you learn k8S choreography, like docker/docker-compose is also built-in, can also be arranged.

Project source code address

  • The back-end

Gitee.com/mldong/mldo…

  • The front end

Gitee.com/mldong/mldo…

Related articles

Walk you through K8S – cluster creation and Hello World

Take you through K8S-ConfigMap and persistent storage

Take you hand in hand to play K8S – complete release of an externally accessible service

Docker-compose k8S-docker advanced Dockerfile and docker-compose

K8s – One click deployment of springboot project

Take you through k8S – One-click deployment of VUE projects

Take you hand in hand to play K8S – common object details

Walk you through k8S-Jenkins installation and assembly line

Walk you through k8S-Jenkins assembly line grammar

Take you hand in hand through the K8S-Jenkins assembly line to launch springboot project

Take you through the K8S-Jenkins assembly line to launch vUE projects

Walk you through k8S – health check survival probe and readiness probe