Start a local Kubernetes environment using kind and Docker

Start a local Kubernetes environment using kind and Docker

introduce

Have you ever spent a whole day trying to get started with Kubernetes? Thanks to some new tools that have emerged recently, you don't have to worry about this anymore.

In this post, I will show you the steps to start a cluster in a single Docker container using kind.

What is Kind?

Since kind is implemented in go language, please make sure you have installed the latest version of golang. According to the developer documentation, go1.11.5 and above are recommended. To install kind, run these commands (may take a while to run)

kind (Kubernetes IN Docker) is a tool for building Kubernetes clusters based on Docker. It is very suitable for building a local development/test environment based on Kubernetes.

go get -u sigs.k8s.io/kind 
kind create cluster

Then confirm that the "kind" cluster is available.

kind get clusters

Setting up kubectl

Similarly, install the latest version of kubernetes-cli using Homebrew or Chocolatey. The latest version of Docker includes Kubernetes functionality but uses an older version of kubectl.

Run this command to check its version number.

kubectl version

Make sure it says GitVersion: "v1.14.1" or higher.

If you find yourself running kubectl via Docker, try using brew link or reordering your environment variables.

Once kubectl and kind are installed, open a bash console and run these commands.

export KUBECONFIG="$(kind get kubeconfig-path)"
kubectl cluster-info

If kind is configured correctly, some information will be displayed. Now you can proceed with the following work. yeah!

Deploy your first application

What do we need to deploy to the cluster? A good choice is Wordpress because it includes MySQL and PHP applications.

Luckily, there is an official primer and it describes it very well. We can try to use the kind cluster we just created to perform most of the steps.

https://kubernetes.io/docs/tutorials/

First, download mysql-deployment.yaml and wordpress-deployment.yaml from this page.

Run two cat commands to create kustomization.yaml. Once these yaml files are prepared, place the files in the respective directories as shown below.

k8s-wp/
kustomization.yaml 
mysql-deployment.yaml 
wordpress-deployment.yaml

Then apply it to your cluster.

cd k8s-wp 
kubectl apply -k ./

If the command is executed successfully you will see output similar to the following:

secret/mysql-pass-7tt4f27774 created
service/wordpress-mysql created
service/wordpress created
deployment.apps/wordpress-mysql created
deployment.apps/wordpress created
persistentvolumeclaim/mysql-pv-claim created
persistentvolumeclaim/wp-pv-claim created

Let's check the status of the cluster by typing these commands:

kubectl get secrets
kubectl get pvc
kubectl get pods
kubectl get services wordpress

Wait for all pods to become Running.

Then, run this command to get the service.

kubectl port-forward svc/wordpress 8080:80

Then open http://localhost:8080/

Look! If you want to view the database, inspect your pod, run a command like this, then open your client app.

kubectl port-forward wordpress-mysql-bc9864c58-ffh4c 3306:3306

in conclusion

kind is a good choice for minikube because it only uses a single Docker container.

By combining it with Kustomze, which is integrated into Kubernetes 1.14, it is even easier to try out Kubernetes on your local machine.

This is the end of this article about using kind and Docker to start a local Kubernetes environment. For more information about using kind and Docker to start a local Kubernetes environment, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Talk about the issue of replacing docker (shim) with containerd in kubernetes1.20
  • How to build a docker private warehouse in centos7 (kubernetes)
  • Docker Practice - Detailed Explanation of Deploying Kubernetes on CentOS7
  • Docker kubernetes dashboard installation and deployment details
  • Detailed explanation of the use of cloud native technology kubernetes scheduling unit pod
  • Introduction to cloud native technology kubernetes (K8S)
  • Cooking dumplings on the relationship between cloud native docker and kubernetes

<<:  MySQL derived table (Derived Table) simple usage example analysis

>>:  Guide to using env in vue cli

Recommend

Detailed explanation of long transaction examples in MySQL

Preface: The "Getting Started with MySQL&quo...

Is mysql a relational database?

MySQL is a relational database management system....

How to use Docker+DockerCompose to encapsulate web applications

Table of contents Technology Stack Backend build ...

Analysis of Linux boot system methods

This article describes how to boot the Linux syst...

How does Vue download non-same-origin files based on URL

Generally speaking, we can have the following two...

Implementation of LNMP for separate deployment of Docker containers

1. Environmental Preparation The IP address of ea...

A brief discussion on the corresponding versions of node node-sass sass-loader

Table of contents The node version does not corre...

Solution to define the minimum height of span has no effect

The span tag is often used when making HTML web pa...

Vue integrates Tencent Map to implement API (with DEMO)

Table of contents Writing Background Project Desc...

Vue3+TypeScript encapsulates axios and implements request calls

No way, no way, it turns out that there are peopl...