k8s中操作pause容器
在k8s中如何操作pause容器,具体步骤如下:一、创建测试pod,如下:apiVersion: v1kind: Podmetadata:name: multi-container-podspec:containers:- name: container-writing-datesimage: alpinecommand: ["/bin/sh"]args: ["-c", "while true;
·
在k8s中如何操作pause容器,具体步骤如下:
一、创建测试pod,如下:
apiVersion: v1
kind: Pod
metadata:
name: multi-container-pod
spec:
containers:
- name: container-writing-dates
image: alpine
command: ["/bin/sh"]
args: ["-c", "while true; do date >> /var/log/output.txt; sleep 10;done"]
- name: container-serving-dates
image: nginx:latest
ports:
- containerPort: 80
启动pod
[root@caas-1 ~]# kubectl apply -f mul-pod.yaml
pod/multi-container-pod configured
二、查看pod所在节点
[root@caas-1 ~]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
multi-container-pod 2/2 Running 0 100s 172.26.28.54 caas-3 <none> <none>
###以上可知pod在caas-3节点上
三、进入pod所在节点,查看对应pause容器ID、pid
[root@caas-3 ~]# docker ps |grep multi 容器ID为f1aa8674bdb9
0ad55e74fb72 fa5269854a5e "/docker-entrypoint.…" 22 minutes ago Up 22 minutes k8s_container-serving-dates_multi-container-pod_default_48c899af-791a-458e-bc4c-8ad797c6201e_0
e10a75b4ba10 alpine "/bin/sh -c 'while t…" 23 minutes ago Up 23 minutes k8s_container-writing-dates_multi-container-pod_default_48c899af-791a-458e-bc4c-8ad797c6201e_0
f1aa8674bdb9 172.16.168.229:5000/pause:3.2 "/pause" 24 minutes ago Up 24 minutes k8s_POD_multi-container-pod_default_48c899af-791a-458e-bc4c-8ad797c6201e_0
查看容器pid
[root@caas-3 ~]# docker inspect f1aa8674bdb9| grep -i Pid
"Pid": 8603,
"PidMode": "",
"PidsLimit": null,
四、进入pause命名空间
[root@caas-3 ~]# nsenter -t 8603 -n bash
[root@caas-3 ~]#
[root@caas-3 ~]#
[root@caas-3 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000
link/ipip 0.0.0.0 brd 0.0.0.0
4: eth0@if132: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1440 qdisc noqueue state UP group default
link/ether 6e:64:76:3e:62:86 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.26.28.54/32 scope global eth0
valid_lft forever preferred_lft forever
之后便可进行各种操作,管理其他容器
更多推荐
已为社区贡献26条内容
所有评论(0)