Skip to content

Commit 9941eaa

Browse files
committed
[ko] Translate docs/tasks/debug-application-cluster/get-shell-running-container.md in Korean
1 parent 3daa802 commit 9941eaa

File tree

2 files changed

+174
-0
lines changed

2 files changed

+174
-0
lines changed
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
---
2+
3+
4+
5+
title: 동작중인 컨테이너의 셸에 접근하기
6+
content_type: task
7+
---
8+
9+
<!-- overview -->
10+
11+
이 페이지는 동작중인 컨테이너에 접근하기 위해 `kubectl exec`을 사용하는
12+
방법에 대해 설명한다.
13+
14+
15+
16+
17+
## {{% heading "prerequisites" %}}
18+
19+
20+
{{< include "task-tutorial-prereqs.md" >}}
21+
22+
23+
24+
25+
<!-- steps -->
26+
27+
## 컨테이너의 셸에 접근하기
28+
29+
이 예시에서는 하나의 컨테이너를 가진 파드를 생성할 것이다. 이 컨테이너는
30+
nginx 이미지를 실행한다. 해당 파드에 대한 설정 파일은 다음과 같다.
31+
32+
{{< codenew file="application/shell-demo.yaml" >}}
33+
34+
파드를 생성한다.
35+
36+
```shell
37+
kubectl apply -f https://k8s.io/examples/application/shell-demo.yaml
38+
```
39+
40+
다음을 통해 컨테이너가 동작하고 있는지 확인할 수 있다.
41+
42+
```shell
43+
kubectl get pod shell-demo
44+
```
45+
46+
동작중인 컨테이너의 셸에 접근한다.
47+
48+
```shell
49+
kubectl exec --stdin --tty shell-demo -- /bin/bash
50+
```
51+
52+
{{< note >}}
53+
kubectl 명령어 인자와 사용하고자 하는 명령어의 인자를 구분하기 위해서는 이중 대시(`--`)를 사용할 수 있다.
54+
{{< /note >}}
55+
56+
셸에 접근해서 다음처럼 루트 디렉토리를 확인해 볼 수 있다.
57+
58+
```shell
59+
# Run this inside the container
60+
ls /
61+
```
62+
63+
접근한 셸에서 다른 명령어도 한번 실행해 보아라. 다음은 실행해 볼
64+
명령의 예시이다.
65+
66+
```shell
67+
# You can run these example commands inside the container
68+
ls /
69+
cat /proc/mounts
70+
cat /proc/1/maps
71+
apt-get update
72+
apt-get install -y tcpdump
73+
tcpdump
74+
apt-get install -y lsof
75+
lsof
76+
apt-get install -y procps
77+
ps aux
78+
ps aux | grep nginx
79+
```
80+
81+
## nginx의 최상단 페이지 작성하기
82+
83+
앞에서 생성한 파드에 대한 설정을 살펴보아라. 파드에는
84+
`emptyDir` 볼륨이 사용되었고, 이 컨테이너는 해당 볼륨을
85+
`/usr/share/nginx/html` 경로에 마운트하였다.
86+
87+
접근한 셸 환경에서 `/usr/share/nginx/html` 디렉터리에 `index.html` 파일을
88+
생성해 보아라.
89+
90+
```shell
91+
# Run this inside the container
92+
echo 'Hello shell demo' > /usr/share/nginx/html/index.html
93+
```
94+
95+
셸 환경에서 nginx 서버에 GET 요청을 시도해보면 다음과 같다.
96+
97+
```shell
98+
# Run this in the shell inside your container
99+
apt-get update
100+
apt-get install curl
101+
curl http://localhost/
102+
```
103+
104+
출력 결과는 여러분이 `index.html` 파일에 작성한 텍스트를 출력할 것이다.
105+
106+
```
107+
Hello shell demo
108+
```
109+
110+
셸 사용이 모두 끝났다면 `exit`을 입력해 종료하라.
111+
112+
```shell
113+
exit # To quit the shell in the container
114+
```
115+
116+
## 컨테이너에서 개별 명령어 실행하기
117+
118+
셸이 아닌 일반적인 커맨드 환경에서 다음처럼 동작중인 컨테이너의
119+
환경 변수를 출력할 수 있다.
120+
121+
```shell
122+
kubectl exec shell-demo env
123+
```
124+
125+
다른 명령어도 한번 실행해 보아라. 다음은 실행해 볼 명령의 예시이다.
126+
127+
```shell
128+
kubectl exec shell-demo -- ps aux
129+
kubectl exec shell-demo -- ls /
130+
kubectl exec shell-demo -- cat /proc/1/mounts
131+
```
132+
133+
134+
135+
<!-- discussion -->
136+
137+
## 파드에 한 개 이상의 컨테이너가 있을 경우 셸에 접근하기
138+
139+
만일 파드에 한 개 이상의 컨테이너가 있을 경우, `kubectl exec` 명령어에
140+
`--container` 혹은 `-c` 옵션을 사용해서 컨테이너를 지정하라. 예를 들어,
141+
여러분이 my-pod라는 이름의 파드가 있다고 가정해 보자. 이 파드에는 _main-app_
142+
_helper-app_ 이라는 이름의 두 컨테이너가 있다. 다음 명령어는 _main-app_
143+
컨테이너에 대한 셸에 접근할 것이다.
144+
145+
```shell
146+
kubectl exec -i -t my-pod --container main-app -- /bin/bash
147+
```
148+
149+
{{< note >}}
150+
축약형 옵션인 `-i``-t` 는 각각 `--stdin``--tty` 옵션에 대응된다.
151+
{{< /note >}}
152+
153+
154+
## {{% heading "whatsnext" %}}
155+
156+
157+
* [kubectl
158+
* exec](/docs/reference/generated/kubectl/kubectl-commands/#exec)를참고한다.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: shell-demo
5+
spec:
6+
volumes:
7+
- name: shared-data
8+
emptyDir: {}
9+
containers:
10+
- name: nginx
11+
image: nginx
12+
volumeMounts:
13+
- name: shared-data
14+
mountPath: /usr/share/nginx/html
15+
hostNetwork: true
16+
dnsPolicy: Default

0 commit comments

Comments
 (0)