6
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GKE Kubernetes NameSpace

Posted at

Kubernetesではnamespaceによる仮想クラスタをサポートしている。namespaceによりリソースの分割などもできる。
※バージョンの違いとかの管理はNameSpaceではなくLabelを使うべき。

  • namespaceを確認する。
$ kubectl get namespaces
NAME          STATUS    AGE
default       Active    17d
kube-system   Active    17d

初期状態では以下の2つのnamespaceが存在している。

* default: ネームスペースを持ってないオブジェクト用
* kube-system: K8sシステムによって生成されるオブジェクのためのネームスペース

テスト用のネームスペースを作成する

$ kubectl create namespace test-namespace
namespace "test-namespace" created

$ kubectl get namespace
NAME             STATUS    AGE
default          Active    17d
kube-system      Active    17d
test-namespace   Active    27s
  • 一時的にnamespaceをセットしたいときは--namespaceフラグを使用する。
$ kubectl get pods
NAME                                     READY     STATUS    RESTARTS   AGE
gcp-cost-3407718879-zrso2                1/1       Running   0          2h
task-processing-time-1436137422-8fwba    1/1       Running   0          1h

$ kubectl --namespace=kube-system get pods
NAME                                                                   READY     STATUS    RESTARTS   AGE
fluentd-cloud-logging-gke-XXX-default-pool-d3a01536-hgn8   1/1       Running   0          17d
fluentd-cloud-logging-gke-XXX-default-pool-d3a01536-vntu   1/1       Running   0          17d
fluentd-cloud-logging-gke-XXX-pool-d3a01536-w0iz   1/1       Running   0          17d
heapster-v1.1.0-2096339923-d5zku                                       2/2       Running   0          17d
kube-dns-v17.1-5acju                                                   3/3       Running   0          17d
kube-dns-v17.1-iwky5                                                   3/3       Running   0          17d
kube-proxy-gke-XXX-default-pool-d3a01536-hgn8              1/1       Running   0          17d
kube-proxy-gke-XXX-default-pool-d3a01536-vntu              1/1       Running   0          17d
kube-proxy-gke-XXX-default-pool-d3a01536-w0iz              1/1       Running   0          17d
kubernetes-dashboard-v1.1.1-i9qbw                                      1/1       Running   0          17d
l7-default-backend-v1.0-nm5cx                                          1/1       Running   0          17d
  • 永続的にnamespaceの設定する
    現在のコンテキストを取得する。
$ export CONTEXT=$(kubectl config view | awk '/current-context/ {print $2}')
$ kubectl config set-context $CONTEXT --namespace=kube-system
context "gke_XXX_us-central1-a_XXX" set.

$ kubectl get pods
※先程と同じ。省略

$ kubectl config view | grep namespace
    namespace: kube-system
6
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?