From c3799773c48b0eb0d2f7c1bf6b5f6529f5ffc646 Mon Sep 17 00:00:00 2001 From: Aris Cahyadi Risdianto Date: Thu, 14 May 2020 21:09:42 +0800 Subject: [PATCH] ID Localization for "Get Shell Running Container" from Task. --- .../get-shell-running-container.md | 147 ++++++++++++++++++ .../id/examples/application/shell-demo.yaml | 16 ++ 2 files changed, 163 insertions(+) create mode 100644 content/id/docs/tasks/debug-application-cluster/get-shell-running-container.md create mode 100644 content/id/examples/application/shell-demo.yaml diff --git a/content/id/docs/tasks/debug-application-cluster/get-shell-running-container.md b/content/id/docs/tasks/debug-application-cluster/get-shell-running-container.md new file mode 100644 index 0000000000..6bbacba023 --- /dev/null +++ b/content/id/docs/tasks/debug-application-cluster/get-shell-running-container.md @@ -0,0 +1,147 @@ +--- +title: Dapatkan _Shell_ Untuk Masuk ke Kontainer yang Sedang Berjalan +content_template: templates/task +--- + +{{% capture overview %}} + +Halaman ini menunjukkan bagaimana cara menggunakan `kubectl exec` untuk +mendapatkan _shell_ untuk masuk ke dalam kontainer yang sedang berjalan. + +{{% /capture %}} + + +{{% capture prerequisites %}} + +{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}} + +{{% /capture %}} + + +{{% capture steps %}} + +## Mendapatkan sebuah _shell_ untuk masuk ke sebuah kontainer + +Dalam latihan ini, kamu perlu membuat Pod yang hanya memiliki satu kontainer saja. Kontainer +tersebut menjalankan _image_ nginx. Berikut ini adalah _file_ konfigurasi untuk Pod tersebut: + +{{< codenew file="application/shell-demo.yaml" >}} + +Buatlah Pod: + +```shell +kubectl apply -f https://k8s.io/examples/application/shell-demo.yaml +``` + +Pastikan bahwa kontainer dalam Pod berjalan: + +```shell +kubectl get pod shell-demo +``` + +Dapatkan _shell_ untuk masuk ke dalam kontainer: + +```shell +kubectl exec -it shell-demo -- /bin/bash +``` + +{{< note >}} + +Simbol tanda hubung ganda "--" digunakan untuk memisahkan antara argumen perintah yang ingin kamu eksekusi pada kontainer dan argumen dari kubectl itu sendiri. + +{{< /note >}} + +Dalam _shell_ kamu, perlihatkan isi dari direktori _root_: + +```shell +root@shell-demo:/# ls / +``` + +Dalam _shell_ kamu, cobalah dengan perintah-perintah yang lainnya. Berikut ini beberapa contoh diantaranya: + +```shell +root@shell-demo:/# ls / +root@shell-demo:/# cat /proc/mounts +root@shell-demo:/# cat /proc/1/maps +root@shell-demo:/# apt-get update +root@shell-demo:/# apt-get install -y tcpdump +root@shell-demo:/# tcpdump +root@shell-demo:/# apt-get install -y lsof +root@shell-demo:/# lsof +root@shell-demo:/# apt-get install -y procps +root@shell-demo:/# ps aux +root@shell-demo:/# ps aux | grep nginx +``` + +## Menulis halaman utama (_root_) untuk nginx + +Lihat kembali pada _file_ konfigurasi untuk Pod kamu. Pod +memiliki _volume_ `emptyDir`, dan kontainer melakukan _mounting untuk _volume_ tersebut +pada `/usr/share/nginx/html`. + +Pada _shell_ kamu, buatlah _file_ `index.html` dalam direktori `/usr/share/nginx/html`: + +```shell +root@shell-demo:/# echo Hello shell demo > /usr/share/nginx/html/index.html +``` + +Pada _shell_ kamu, kirimkan sebuah permintaan (_request_) GET ke server nginx. + +```shell +root@shell-demo:/# apt-get update +root@shell-demo:/# apt-get install curl +root@shell-demo:/# curl localhost +``` + +Tampilan akan menunjukkan teks yang kamu tulis pada _file_ `index.html`. + +```shell +Hello shell demo +``` + +Setelah kamu selesai dengan _shell_ kamu, ketiklah `exit`. + +## Menjalankan perintah individu dalam sebuah kontainer + +Pada jendela (_window_) perintah biasa, bukan pada _shell_ kamu dalam kontainer, +lihatlah daftar lingkungan variabel pada kontainer yang sedang berjalan: + +```shell +kubectl exec shell-demo env +``` + +Cobalah dengan menjalankan perintah lainnya. Berikut ini beberapa contoh diantaranya: + +```shell +kubectl exec shell-demo ps aux +kubectl exec shell-demo ls / +kubectl exec shell-demo cat /proc/1/mounts +``` + +{{% /capture %}} + +{{% capture discussion %}} + +## Membuka sebuah _shell_ ketika sebuah Pod memiliki lebih dari satu kontainer + +Jika sebuah Pod memiliki lebih dari satu kontainer, gunakanlah `--container` atau `-c` untuk +menentukan kontainer yang dimaksud dalam perintah `kubectl exec`. Sebagai contoh, +misalkan kamu memiliki Pod yang bernama my-pod, dan Pod tersebut memiliki dua kontainer +yang bernama main-app dan helper-app. Perintah berikut ini akan membuka sebuah +_shell_ ke kontainer dengan nama main-app. + +```shell +kubectl exec -it my-pod --container main-app -- /bin/bash +``` + +{{% /capture %}} + + +{{% capture whatsnext %}} + +* [kubectl exec](/docs/reference/generated/kubectl/kubectl-commands/#exec) + +{{% /capture %}} + + + diff --git a/content/id/examples/application/shell-demo.yaml b/content/id/examples/application/shell-demo.yaml new file mode 100644 index 0000000000..9eb140d80f --- /dev/null +++ b/content/id/examples/application/shell-demo.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Pod +metadata: + name: shell-demo +spec: + volumes: + - name: shared-data + emptyDir: {} + containers: + - name: nginx + image: nginx + volumeMounts: + - name: shared-data + mountPath: /usr/share/nginx/html + hostNetwork: true + dnsPolicy: Default