First of all, we should briefly understand the three core concepts of this article:
Memory is recommended to be at least 4G.
Q: How do I view the host name?
A: Execute the command hostname.
Q: How to modify the host name?
Answer: The way to take effect permanently: execute the command vi /etc/hostname, remove the first line (which cannot be commented out, but needs to be removed), then rewrite the custom hostname (pay attention to the naming standard), and it will take effect after saving and restarting;
Effective temporarily: execute the following command
Q: How do I view the MAC address?
Answer: execute the command ip link, and then look at your first network card.
Q: How do I view product_uuid?
A: execute the command sudocat/sys/class/DMI/id/product _ uuid.
Note: The port range of 30000-32767 is the range that we must set to create a service port (if it exceeds the set range, there will be a restriction prompt and the creation will fail), which is stipulated by K8S.
In addition, if you want to turn off the firewall directly, you can also.
⑥ Switching must be disabled.
The total number of exchanges is greater than 0, indicating that the exchange partition is open.
Q: How do I turn off the exchange?
Answer: Edit the file /etc/fstab, add a # before the exchange line, and restart the server.
Check the partition status again, it has taken effect.
Common container runtime (runtime):
The container engine used in this article is Docker.
View version after installation:
When there is a strange exception that may be related to Docker engine, you can try to uninstall Docker and reinstall it, but be sure to pay attention to whether you need to back up images, containers, volumes or configuration files.
The following steps are recorded to uninstall the Docker engine:
① uninstall the Docker engine, CLI and Containerd package:
② Images, containers, volumes or custom configuration files on the host will not be automatically deleted. Delete all mirrors, containers and volumes:
③ If the configuration file contains illegal characters, it will cause startup failure, so we need to delete it and rebuild it.
At this point, the Docker engine has been uninstalled.
Official website used Google's Yum! Source, and because it could not be connected in China, it was replaced by Yum! Source provided by Ali.
① Installation
As can be seen from the installation information, the version number is 1.22.
Installation:
Kubeadm x86 _ 641.22.4-0 Kubernetes 9.3m.
kubectl x86 _ 64 1 . 22 . 4-0 kubernetes 9.7M
Cooper Wright x86_64 1.22.4-0 Cooper Nate 20m
② Start.
This is a driver. Be careful not to confuse cgroup with cgroupfs.
Quote an official passage
Because Kubean ADM manages kubelet as a system service, we recommend using systemd driver instead of cgroupfs driver for Kubean ADM-based installation.
Kubeadm ADM uses systemd driver by default, and our docker default driver is cgroupfs(docker information can be viewed), so we need to change Docker driver to systemd.
① Edit Docker configuration file.
② Restart Docker service
Docker info looks at the driver information again, and it has become systemd.
The minimum configuration of the working node is here.
① Description of mirror source parameters
By default, kubeadm ADM will pull images from k8s.gcr.io warehouse, which is impossible in China. The official document clearly indicates that it is allowed to use other imageRepository instead of k8s.gcr.io
-image-repository your mirror repository address.
Next, I found some domestic mirror sources and made a simple analysis.
Based on the above statistics, I choose the mirror source of Alibaba Cloud.
② Description of IP address range parameters
-pod-network-CIDR = 192. 168 . 0 . 0/ 16
Note: If192.168.0.0/16 is already used in your network, you must select a different pod network CIDR and replace192.168.0.0/in the above command.
Cluster initialization command:
Because I use a demonstration machine, I have published complete execution information here for your reference. We must pay attention to protecting sensitive information in our daily work (my ip address range is customized for the following function demonstration, and it usually takes several minutes to download the image file for the first time in init).
As shown above, the cluster has been successfully initialized. At this time, be sure to pay attention to the last part of the operation prompt of the execution result above. I have marked the three steps that need to be performed after the initialization is successful.
Note: If the parameters need to be adjusted after the initialization is successful, you can execute kubeadm reset to restore the changes made by kubeadm init or kubeadm join as much as possible.
To start using your cluster, you need to run the following command as an ordinary user:
Before you start using the cluster, if you are a normal user (not root), you need to execute the following command:
Or, if you are root, you can run:
Alternatively, if you use root, you can execute the following command:
(Note: The export is only temporary, which means it needs to be performed once every time you log in. )
The network configuration is Pod's network, and my network plug-in is calico.
Cidr is an ip address range. If you use pod cdr192.168.0.0/16, please skip to the next step.
However, the POCDR used in this article is192.100.016, so I need to uncomment the CALICO_IPV4POOL_CIDR variable in the list and set it to the same value as the POCDR I selected. (Pay attention to the format and alignment. )
You can customize the list according to your needs, and generally skip this step if you don't need it.
Execute the join command on all work nodes (copy the join cluster command returned after successful initialization before and execute it on all work nodes).
View the status of all nodes on the master node.
A cluster has been created here.
Finally, I will install K8S visual interface kubernetes-dashboard for our daily use.
① Download yaml file.
② Modify yaml file, add type and node port, so that the service can be accessed externally.
③ Install and check the operation.
④ Create a new user
Save and apply the file after creating it.
⑤ Get the interface login token.
⑥ Log in to the dashboard.
192.168.189.128 is my main server ip. It should be noted that https must be used, and ie kernel mode cannot be used.
Copy the generated token into the input box, and then click Login.
The dashboard installation configuration is complete.
Q: How do I view resources?
A: Execute the following command on the master server to view the resources (-o wide means to display more detailed information).
① View all nodes
② View all namespaces
③ Check the pod in the namespace.
④ View pane of all namespaces.
⑤ Check the running status of pod in namespace in real time.
Q: There is an exception in kubeadm join [wrong port-10250]: the port 10250 is in use. How to solve it?
A: This is because you failed to join before, and you need to reset kubeadm before you can join again.
Q: How to solve the problem that the network card suddenly disappears when testing on the virtual machine (off-topic problem record)?
A:
① Confirm the missing network card information, starting with ens (optional step).
Profile -a
② Execute the following commands to solve the problem
Q: How do I view the K8S version?
A: kubectl version
Q: What if the join command is forgotten or expired?
A:
Generate a that never expires.
24-hour generational aging
Q: What should I do if the Pod keeps restarting and there are no other error messages?
A: This is usually because there is only one master node in your cluster, and there is no working node. By default, the creation of the master node is tainted, that is, it is not allowed to schedule new PODs. If necessary (of course, this is not recommended), you need to remove the stains on the master. To delete a stain, you can execute the following command.
It should return the following.