偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

如何在Kubernetes中創(chuàng)建命名空間?

譯文
開源
多個團隊使用同一個集群時,命名空間很有用。有可能發(fā)生名稱沖突時使用命名空間。它可能是多個集群之間的虛擬墻。比如說,我們在Kubernetes集群中不可能有名稱一樣的pod,但使用命名空間,我們實際上可以劃分集群,擁有名稱一樣的pod。

【51CTO.com快譯】

多個團隊使用同一個集群時,命名空間很有用。有可能發(fā)生名稱沖突時使用命名空間。它可能是多個集群之間的虛擬墻。比如說,我們在Kubernetes集群中不可能有名稱一樣的pod,但使用命名空間,我們實際上可以劃分集群,擁有名稱一樣的pod。

命名空間的一些重要功能如下。

  • •它使用同一個命名空間幫助pod到pod的通信。
  • •它充當駐留在同一個理集群上的虛擬集群。
  • •它在團隊及其環(huán)境之間提供了邏輯隔離。

我們在本文中將創(chuàng)建一個命名空間,并在剛創(chuàng)建的命名空間中創(chuàng)建一個pod。我們還將看到如何將命名空間設(shè)置為默認命名空間。

前提條件

  • 有至少1個worker節(jié)點的Kubernetes集群

如果您想學(xué)習(xí)創(chuàng)建Kubernetes集群,請點擊此處(https://www.howtoforge.com/setup-a-kubernetes-cluster-on-aws-ec2-instance-ubuntu-using-kubeadm/)。本指南將幫助您在AWS Ubuntu 18.04 EC2實例上創(chuàng)建有1個Master和2個節(jié)點的Kubernetes集群。

我們要做什么?

  • 創(chuàng)建命名空間

創(chuàng)建命名空間

想列出Kubernetes集群中所有可用的命名空間,請執(zhí)行以下命令。 

  1. kubectl get namespace #Get all namespace in the cluster 

圖1

現(xiàn)在,不妨在并不存在的特定命名空間中創(chuàng)建pod。

想在“test-env”命名空間中創(chuàng)建一個pod,執(zhí)行以下命令。 

  1. kubectl run nginx --image=nginx --namespace=test-env #Try to create a pod in the namespace that does not exist. 

pod不會在不存在的命名空間中創(chuàng)建,因此我們先要創(chuàng)建一個命名空間。

想創(chuàng)建命名空間“test-env”,執(zhí)行以下命令。 

  1. kubectl create namespace test-env #Create a namespace  
  2. kubectl get namespace #Get a list of namespaces  

圖2

現(xiàn)在,我們有了想在其中創(chuàng)建pod的命名空間。

想在我們創(chuàng)建的這個空間中創(chuàng)建pod,將--namespace = test-env選項傳遞給命令。 

  1. kubectl run nginx --image=nginx --namespace=test-env #Create a pod in the namespace. 

如果您試圖在未指定命名空間的情況下創(chuàng)建pod,就無法獲得pod的詳細信息。 

  1. kubectl get pods #Get a list of pods 

想獲得屬于“test-env”命名空間的pod的詳細信息,使用以下命令。 

  1. kubectl get pods --namespace=test-env #Get a list of pods in the specified namespace 

圖3

如果您想把命名空間設(shè)置為默認命名空間,從而不需要在命令中指定命名空間選項,請使用以下命令。 

  1. kubectl config set-context --current --namespace=test-env #Set default namespace 

現(xiàn)在,無需在命令中指定命名空間即可獲得pod的詳細信息。 

  1. kubectl get pods #Get a list of pods from the default namespace 

圖4

想切換到默認命名空間,請使用以下命令。 

  1. kubectl config set-context --current --namespace=default #Check the namespace to default  
  2. kubectl get pods #Get a list of pods  

圖5

想檢查哪個是默認命名空間,請使用以下命令。 

  1. kubectl config view --minify | grep namespace: #Extract the namespace from the kubernetes config file.  
  2. kubectl config set-context --current --namespace=test-env #Set default namespace in the config file.  
  3. kubectl config view --minify | grep namespace:  

圖6

檢查哪些Kubernetes資源是命名空間,執(zhí)行以下命令。 

  1. kubectl api-resources --namespaced=true #Get Kubernetes objects which can be in a namespaces 

圖7

想查看哪些Kubernetes資源不在命名空間中,請使用以下命令。 

  1. kubectl api-resources --namespaced=false #Get a list of Kubernetes objects that can never be in a namespace 

圖8

您可以使用下述命令獲得命名空間的詳細信息。 

  1. kubectl get namespaces #Get a list of namespaces.  
  2. kubectl describe namespace test-env #Get details of a namespace.  

圖9

還可以使用.yml文件創(chuàng)建命名空間。 

  1. vim namespace-using-file.yml #Create a namespace definition file 

圖10

執(zhí)行以下命令以創(chuàng)建對象定義文件中指定的命名空間。 

  1. kubectl create -f namespace-using-file.yml #Create a namespace using a .yml file  
  2. kubectl get namespaces #Get a list of namespaces  

圖11

您不再需要命名空間時,只需使用以下命令即可刪除它。 

  1. kubectl get namespaces #Get a list of namespaces  
  2. kubectl delete namespaces env-prod test-env #Delete a namespace  
  3. kubectl get namespaces #Get a list of namespaces  

圖12

結(jié)論

我們在本文中了解了命名空間、創(chuàng)建命名空間、更改默認命名空間,以及檢查命名空間中存在和不存在的Kubernetes資源。我們還看到了如何在我們選擇的命名空間中創(chuàng)建Kubernetes對象(這里是pod)。

原文標題:How to create Namespaces in Kubernetes

【51CTO譯稿,合作站點轉(zhuǎn)載請注明原文譯者和出處為51CTO.com】

 

責(zé)任編輯:龐桂玉 來源: 51CTO
相關(guān)推薦

2019-07-30 10:33:01

2020-07-20 07:00:00

KubernetesHostPath

2022-11-18 14:58:34

JavaScript語言TypeScript

2019-07-29 10:00:10

Windows 10節(jié)省空間Windows

2023-02-06 17:49:35

Linux符號鏈接

2024-07-30 08:00:00

Kubernetes數(shù)據(jù)庫

2023-07-29 11:54:44

KuberneteNFS

2022-10-19 21:24:24

臨時表空間Oracle

2022-11-11 09:01:08

SwiftUI條形圖子視圖

2015-04-09 11:05:55

openstack公有云openstack鏡像

2019-05-14 11:00:07

LinuxSSH別名

2011-05-04 09:11:30

RPM包Linux

2022-06-27 05:48:24

Kubernetes容器

2021-02-18 17:00:52

Linux歸檔文件

2022-04-01 07:35:45

IDEAJavaWeb 項目

2020-07-09 13:10:42

GIMP曲線文本應(yīng)用

2009-11-23 20:05:29

ibmdwLotus

2022-03-15 07:55:09

JavaScript線性儀表圖開發(fā)

2023-09-27 23:24:50

C++鏈表

2018-01-26 09:02:30

LinuxPDF創(chuàng)建視頻
點贊
收藏

51CTO技術(shù)棧公眾號