Take your hand to quickly create a kubernetes cluster with Docker (with detailed code and hands-on video)

Source: Internet
Author: User
Tags base64 curl k8s


Production 丨 Docker Co., Ltd (ID:DOCKER-CN)

Compiling 丨 small East

Every Monday, five 6:10 P.M. with you see not scattered


Say in front


Today brings you a tutorial on creating a kubernetes cluster quickly with Docker. This tutorial is based on my previous article "10-minute deployment of kubernetes cluster," updated, condensed. This tutorial has been verified by me many times, and it has some guiding significance. Especially when you want to create a cluster in the cloud or locally as soon as possible. If you have any questions about this tutorial, you can refer to the demo video at the end of the article.



first, the selection of host


I will use Ubuntu 16.04 in this tutorial so that you can copy/paste all the commands. Here are a few of my personal testing environment, you can combine the actual situation as a reference:


digitalocean--Developer Cloud


civo--, UK developer Cloud



packet--Bare Metal Cloud



2 i7 Dell hosts--In my home


1. Configure the Machine


I recommend that you test with at least 3 hosts so that we have a master node and two working nodes.


There are two more points that need your attention:


Ideally choose a dual-core host with at least 2GB of RAM;


If you can select a custom user name when you configure the host, you will need to choose a custom username to discard the root selection. For example, Civo provides an option for ubuntu,civo or root;


Now perform the following steps on each machine, which may take you 5-10 minutes. If you think this process is too slow, you can also enter the following command to use the utility script I made:


$ CURL-SL https://gist.githubusercontent.com/alexellis/e8bbec45c75ea38da5547746c0ca4b0c/raw/ 23fc4cd13910eac646b13c4f8812bab3eeebab4c/configure.sh | Sh


2, login and install Docker


Next we're going to install Docker from the Ubuntu Apt Library. Although it's an old version of Docker, it's enough for the kubernetes test we're going to take.

$ sudo apt-get update \

&& sudo apt-get install-qy docker.io


3. Disable swap file


This is a mandatory step for kubernetes testing. The easiest way to do this is to edit the/etc/fstab and comment out what is pointing to swap.


Enter "sudo swapoff-a" to save and reboot.


Disabling swap memory may appear to be a strange requirement at the outset. If you are curious about this step, you can click " read the original " at the end of the text to get more details.


4. Installation Kubernetes


$ sudo apt-get update \

&& sudo apt-get install-y apt-transport-https \

&& Curl-s HTTPS://PACKAGES.CLOUD.GOOGLE.COM/APT/DOC/APT-KEY.GPG | sudo apt-key add-

$ echo "Deb http://apt.kubernetes.io/kubernetes-xenial main" \

| sudo tee-a/etc/apt/sources.list.d/kubernetes.list \

&& sudo apt-get update

$ sudo apt-get update \

&& sudo apt-get install-y \

Kubelet \

KUBEADM \

Kubernetes-cni


5. Create a cluster


At this point, we will create the cluster by using the Kubeadm startup Master node, enter the following command on the master node (you can choose to ignore any warnings):

$ sudo kubeadm init


If you omit a step or have any problems, Kubeadm will prompt you at this point.


Obtain a copy of the Kube profile:


Mkdir-p $HOME/.kube

sudo cp-i/etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $ (id-u): $ (id-g) $HOME/.kube/config


Make sure you have noted your connection token.


$ sudo kubeadm join--token c30633.d178035db2b4bb9a 10.0.0.5:6443--discovery-token-ca-cert-hash sha256:



second, the installation of network


Many network vendors can provide services for kubernetes, but all need to be set up, so I'm going to use weave Net in Weaveworks for a demo because it's one of the most popular choices in the Kubernetes community. It can work without additional configuration.

$ kubectl apply-f "https://cloud.weave.works/k8s/net?k8s-version=$" (Kubectl version | Base64 | Tr-d ' \ n ') '


If you have a private network enabled on your host, you may need to change your private subnet and use Weavenet to assign IP addresses to pods (containers). You can refer to the following demo case:

$ CURL-SL "https://cloud.weave.works/k8s/net?k8s-version=$" (Kubectl version | Base64 | Tr-d ' \ n ') &env. Ipalloc_range=172.16.6.64/27 "| Kubectl Apply-f-


Weave also has a very cool visualization tool--weave Cloud. Weave Cloud is a free tool that will show you the path flow between the pods. You can access (Https://www.weave.works/blog/openfaas-gke) to view related demo cases for Openfaas projects.


Third, join the work node to the cluster


With the KUBEADM join command, you can switch to any of your work nodes.


Iv. Summary


That's it--my demo's done. Now you have a cluster that you can run and deploy your application to. Enter the Kubectl get nodes command to view the node (shown in the following figure). If you need to set up the dashboard UI, see the Kubernetes documentation.



If you have any questions about this tutorial, you can refer to my demo video and let me take you quickly to create a kubernetes cluster.




Click on the title below to read more dry goods


The Docker for Windows Desktop now supports the Kubernetes 1.8 version, which is simple, secure, and instantly available.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.