UTS Linux kernel is the Namespace Namespace (namespace) a subsystem mainly used to complete the isolation of the container and HOSTNAME domain while preserving the kernel name, version, and type of underlying system structure information.
UTS is a flat namespace structure, there is no hierarchical relationship between the different namespaces.
Uts namespace information is used to isolate the system, so that the user to view the information in the container of the current container system, versions, different from the host, the kernel unified management of the current system information through a plurality of containers uts_namespace each container has its own corresponding to uts_namespace, the kernel used to isolate the name of the container, version information, view the different containers are of their own information, can view each other
See the current status of the process tree
Start a terminal View
[root@k8s-nginx1 ~]# pstree -pl systemd(1)─┬─NetworkManager(793)─┬─{NetworkManager}(816) │ └─{NetworkManager}(818) ├─agetty(803) ├─auditd(765)───{auditd}(766) ├─crond(798) ├─dbus-daemon(788) ├─irqbalance(796) ├─lvmetad(613) ├─master(1283)─┬─pickup(4030) │ └─qmgr(1285) ├─nginx(1114)───nginx(1115) ├─polkitd(791)─┬─{polkitd}(809) │ ├─{polkitd}(810) │ ├─{polkitd}(811) │ ├─{polkitd}(812) │ ├─{polkitd}(815) │ └─{polkitd}(820) ├─rngd(794) ├─rsyslogd(1027)─┬─{rsyslogd}(1131) │ └─{rsyslogd}(1132) ├─sshd(1029)───sshd(4052)───bash(4054)───pstree(4088) ├─systemd-journal(588) ├─systemd-logind(792) ├─systemd-udevd(617) └─tuned(1023)─┬─{tuned}(1552) ├─{tuned}(1553) ├─{tuned}(1555) └─{tuned}(1556)
View the current process uts, $$ indicates the PID of the current process, this is equivalent to 4054
Readlink view namespace using the inode number
[root@k8s-nginx1 ~]# readlink /proc/$$/ns/uts /proc/4054/ns/uts uts:[4026531838] uts:[4026531838]
View the current process hostname
[root@k8s-nginx1 ~]# hostname k8s-nginx1
Create a new uts namespace to view the current status of the process tree
[root@k8s-nginx1 ~]# unshare --uts bash [root@k8s-nginx1 ~]# pstree -pl systemd(1)─┬─NetworkManager(793)─┬─{NetworkManager}(816) │ └─{NetworkManager}(818) ├─agetty(803) ├─auditd(765)───{auditd}(766) ├─crond(798) ├─dbus-daemon(788) ├─irqbalance(796) ├─lvmetad(613) ├─master ( 1283 ) ─┬─pickup ( 4030 ) │ └─qmgr ( 1285 ) ├─nginx ( 1114 ) ───nginx ( 1115 ) ├─polkitd ( 791 ) ─┬─ {polkitd} ( 809 ) │ ├ ─ {polkitd} ( 810 ) │ ├─ {polkitd} ( 811 ) │ ├─ {polkitd} ( 812 ) │ ├─ {polkitd} ( 815 ) │ └─ {polkitd} ( 820 ) ├─rngd ( 794 ) ├─rsyslogd ( 1027 ) ─┬─} {rsyslogd ( 1131 ) │ └─} {rsyslogd ( 1132 ) ├─sshd ( 1029 ) ───sshd ( 4052 ) ───bash ( 4054 ) ───bash ( 4091 ) ───pstree ( 4100 ) # than above a bash (4091) ├─systemd -journal ( 588 ) ├─systemd -logind ( 792 ) ├─systemd -udevd ( 617 ) └─tuned ( 1023 ) ─ Tuned} {┬─ ( 1552 ) ├─} {Tuned ( 1553) ├─{tuned}(1555) └─{tuned}(1556)
4054 and 4091 of different uts inode number, description of these two threads in a different namespace
[root@k8s-nginx1 ~]# readlink /proc/$$/ns/uts /proc/4091/ns/uts uts:[4026532430] uts:[4026532430]
Set the current process hostname
The new hostname does not take effect immediately, execute exec bash, bash the use of the new replace the current bash, the hostname into force
[root@k8s-nginx1 ~]# hostname namespace-01 [root@k8s-nginx1 ~]# exec bash [root@namespace-01 ~]# hostname namespace-01
Another start a terminal
View the process tree
[root@k8s-nginx1 ~]# pstree -pl systemd(1)─┬─NetworkManager(793)─┬─{NetworkManager}(816) │ └─{NetworkManager}(818) ├─agetty(803) ├─auditd(765)───{auditd}(766) ├─crond(798) ├─dbus-daemon(788) ├─irqbalance(796) ├─lvmetad(613) ├─master(1283)─┬─pickup(4030) │ └─qmgr(1285) ├─nginx(1114)───nginx(1115) ├─polkitd(791)─┬─{polkitd}(809) │ ├─{polkitd}(810) │ ├─{polkitd}(811) │ ├─{polkitd}(812) │ ├─{polkitd}(815) │ └─{polkitd}(820) ├─rngd(794) ├─rsyslogd(1027)─┬─{rsyslogd}(1131) │ └─{rsyslogd}(1132) ├─sshd(1029)───sshd(4052)─┬─bash(4054)───bash(4091) │ └─bash(4115)───pstree(4130) ├─systemd-journal(588) ├─systemd-logind(792) ├─systemd-udevd(617) └─tuned(1023)─┬─{tuned}(1552) ├─{tuned}(1553) ├─{tuned}(1555) └─{tuned}(1556)
Uts view the current process
[root@k8s-nginx1 ~]# readlink /proc/$$/ns/uts /proc/4115/ns/uts uts:[4026531838] uts:[4026531838]
View the current process hostname
[root@k8s-nginx1 ~]# hostname k8s-nginx1
Create a new view process uts namespace tree
[root@k8s-nginx1 ~]# unshare --uts bash [root@k8s-nginx1 ~]# pstree -pl systemd(1)─┬─NetworkManager(793)─┬─{NetworkManager}(816) │ └─{NetworkManager}(818) ├─agetty(803) ├─auditd(765)───{auditd}(766) ├─crond(798) ├─dbus-daemon(788) ├─irqbalance(796) ├─lvmetad(613) ├─master ( 1283 ) ─┬─pickup ( 4030 ) │ └─qmgr ( 1285 ) ├─nginx ( 1114 ) ───nginx ( 1115 ) ├─polkitd ( 791 ) ─┬─ {polkitd} ( 809 ) │ ├ ─ {polkitd} ( 810 ) │ ├─ {polkitd} ( 811 ) │ ├─ {polkitd} ( 812 ) │ ├─ {polkitd} ( 815 ) │ └─ {polkitd} ( 820 ) ├─rngd ( 794) ├─rsyslogd ( 1027 ) ─┬─} {rsyslogd ( 1131 ) │ └─} {rsyslogd ( 1132 ) ├─sshd ( 1029 ) ───sshd ( 4052 ) ─┬─bash ( 4054 ) ───bash ( 4091 ) │ └─bash ( 4115 ) ───bash ( 4133 ) ───pstree ( 4142 ) # new process 4133 ├─systemd -journal ( 588 ) ├─systemd -logind ( 792 ) ├─systemd -udevd ( 617 ) └─tuned (1023)─┬─{tuned}(1552) ├─{tuned}(1553) ├─{tuned}(1555) └─{tuned}(1556)
View the current process uts
[root@k8s-nginx1 ~]# readlink /proc/$$/ns/uts /proc/4133/ns/uts uts:[4026532431] uts:[4026532431]
[root@k8s-nginx1 ~]# hostname namespace-02 [root@k8s-nginx1 ~]# exec bash [root@namespace-02 ~]# hostname namespace-02