When you modify the host name, you can directly use the tools provided by the system.
[root@localhost centos]# hostnamectl
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: 89bf177f78dc49f6b4954e1e9511e267
Boot ID: 8f46edc8b7b648f58d5d4c1f3c15cbee
Virtualization: vmware
Operating System: CentOS Linux 8
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-240.10.1.el8_3.x86_64
Architecture: x86-64
[root@localhost centos]# sudo hostnamectl set-hostname k8s-slave
[root@localhost centos]# hostnamectl
Static hostname: k8s-slave
Icon name: computer-vm
Chassis: vm
Machine ID: 89bf177f78dc49f6b4954e1e9511e267
Boot ID: 8f46edc8b7b648f58d5d4c1f3c15cbee
Virtualization: vmware
Operating System: CentOS Linux 8
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-240.10.1.el8_3.x86_64
Architecture: x86-64
[root@localhost centos]# cat /etc/hostname
k8s-slave
[root@localhost centos]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@localhost centos]# vi /etc/hosts
[root@localhost centos]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.187.151 k8s-slave
[root@localhost centos]#