“This is the first day of my participation in the First Challenge 2022. For details: First Challenge 2022”

Installation is one of the biggest difficulties in learning k8S, and I have given up learning several times because of installation problems. Therefore, I don’t want installation to be a stumbling block to learning k8S. So, I organized my experience into a shell script and really implemented a one-click installation. No more headaches for installing k8S! Without further ado, let’s get started.

Important caveat: There are two issues you need to overcome if you are going to settle into k8S

  1. Machine configuration. K8s has high requirements for machine configuration, especially for us to learn, generally installed in the local VIRTUAL machine. No doubt, the machine configuration is even higher. It is recommended that the host memory be greater than or equal to 8 GB.
  2. Network problems. K8s has a lot of stuff on foreign websites, which is very painful for domestic users. So you know (^ del ^), preferably Google. You can contact me if you have difficulties.

Note: The installation methods in this tutorial are for learning only and are not recommended for production environments.

1. Kubernetes deployment environment requirements

  • One or more machines, operating system Centos 7.X-86_X64
  • Hardware configuration: memory 2GB or 2G+, CPU 2 core or CPU 2 core +
  • The machines in the cluster can communicate with each other
  • Each machine in the cluster can access the Internet, and the image needs to be pulled
  • Disabling swap partitions

2. Install k8s

2.1 Installation Procedure

  • Download the installation script install_k8s.sh
  • Upload it to the machine to be installed and assign execution permissionchmod +x install_k8s.sh
  • Execute the scriptsh install_k8s.sh

Installation steps are so easy ^_^

2.2 Installation Process Description

  • Step 1 Install Docker
  • Step 2: Install Docker-compose
  • Step 3 install K8S

Installation will have interactive process, do not leave. The interaction is as follows:

  • Ask if you want to install Docker (if you have already installed docker, select No)
  • Ask whether docker-compose should be installed (optional step, choose no, and docker-compose often fails to be installed due to network problems)

  • Ask whether to install K8S

  • Enter the master IP address of K8S, which is actually the IP address of the current installation machine

Description:

  1. Scripts can be executed repeatedly
  2. If an error occurs during installation, check the FAQ at the bottom of this article. If you don’t have any questions in the FAQ, feel free to leave a comment in this article. I will take time to check and solve it.
  3. Install log files in/var/log/install_k8s.logThe node join command is found in the installation log as follows:

    Copy the join command to the Node machine and add it to the K8S cluster. Attached is a copy of my installation log:install_k8s.log

2.3 Installation Verification

  • Verify that docker is installed successfullydocker -v
  • Verify that Docker-compose is successfully installeddocker-compose -v
  • Verify that the K8S is installed successfullykubectl get nodes

That’s already done in the scriptTo stainUsing kubeadmin to deploy K8S, by default, pod can not be scheduled on the master.

Wait for a while, then passkubectl get nodesCheck that the master status is normal.



Next, have fun! O ha ha ~ O (studying studying)

3. Test the cat

Let’s first deploy nginx to see if the environment we just deployed is working properly.

  • Start the nginx podkubectl run nginx-pod --image=nginx
  • Check the podkubectl get pod -o wide

  • Access to the podThe curl 10.244.0.4. In this case, you can only access the cluster IP address
  • Expose the POD as a Servicekubectl expose pod nginx-pod --type=NodePort --port=80
  • Look at the servicekubectl get svc. Map a random port to the host as follows:
  • At this point, nginx-pod is exposed to the extranet and can pass throughcurl localhost:31493Access [here port yours may be different from mine].

Ok, at this point, you can basically declare that your K8S has been built successfully! Surprised not surprise O(∩_∩)O ha ha ~

4. To summarize

In summary, the entire installation steps are as follows:

  1. Preparing a host (CPU >2c memory >2G OS >Centos7)
  2. Keep the Internet up and running (Google is preferred)
  3. Downloading the Installation script
  4. Upload to the server and execute

The whole process could not have been simpler.  ̄□ ̄ | |

5. FAQ

Q: [ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1 A: to performsysctl -w net.ipv4.ip_forward=1

Welcome feedback if installation problems (^▽^)