博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
k8s--如何使用Namespaces
阅读量:6615 次
发布时间:2019-06-24

本文共 3535 字,大约阅读时间需要 11 分钟。

Namespaces 使用示例

  • Viewing namespaces
  • Creating a new namespace
  • Deleting a namespace
  • Subdividing your cluster using Kubernetes namespaces
Viewing namespaces
[root@tvm-00 test]# kubectl get namespacesNAME          STATUS    AGEdefault       Active    5dkube-public   Active    5dkube-system   Active    5d
Creating a new namespace
[root@tvm-00 ~]# cat ~/k8s_install/test/ns/dev.yamlapiVersion: v1kind: Namespacemetadata:  name: ns-dev  labels:    name: envDev[root@tvm-00 ~]# kubectl apply -f ~/k8s_install/test/ns/dev.yamlnamespace "ns-dev" created[root@tvm-00 ~]# kubectl get nsNAME          STATUS    AGEdefault       Active    5dkube-public   Active    5dkube-system   Active    5dns-dev        Active    26s[root@tvm-00 ~]# kubectl describe namespaces/ns-dev Name: ns-dev Labels: name=envDev Annotations: kubectl.kubernetes.io/last-applied-configuration={ "apiVersion":"v1","kind":"Namespace","metadata":{ "annotations":{},"labels":{ "name":"envDev"},"name":"ns-dev","namespace":""}} Status: Active No resource quota. No resource limits.
Deleting a namespace
[root@tvm-00 ~]# kubectl delete namespaces/ns-devnamespace "ns-dev" deleted[root@tvm-00 ~]# kubectl get nsNAME          STATUS        AGEdefault       Active        5dkube-public   Active        5dkube-system   Active        5dns-dev        Terminating   1m[root@tvm-00 ~]# kubectl get nsNAME          STATUS    AGEdefault       Active    5dkube-public   Active    5dkube-system   Active    5d
Subdividing your cluster using Kubernetes namespaces
### 创建 2 个环境 envDev, envTest[root@tvm-00 ~]# cat ~/k8s_install/test/ns/test.yamlapiVersion: v1kind: Namespacemetadata:  name: ns-test  labels:    name: envTest[root@tvm-00 ~]# kubectl apply -f ~/k8s_install/test/ns/dev.yaml[root@tvm-00 ~]# kubectl apply -f ~/k8s_install/test/ns/test.yaml[root@tvm-00 ~]# kubectl get ns --show-labels NAME STATUS AGE LABELS default Active 5d 
kube-public Active 5d
kube-system Active 5d
ns-dev Active 7m name=envDev ns-test Active 2m name=envTest 注意:这里的例子是使用的kubectl命令行方式,实际使用还是yaml配置文件清晰好用 ### 假设我们要将服务 s1 的版本 0.9 发布到 envDev,服务 s1 的版本 0.7 发布到 envTest [root@tvm-00 ~]# kubectl -n ns-dev run s1 --image=opera443399/whoami:0.9 --replicas=2 deployment "s1" created [root@tvm-00 ~]# kubectl get deploy NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE app-whoami 3 3 3 3 1h [root@tvm-00 ~]# kubectl get deploy -n ns-dev NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE s1 2 2 2 2 18s [root@tvm-00 ~]# kubectl -n ns-test run s1 --image=opera443399/whoami:0.7 --replicas=2 deployment "s1" created [root@tvm-00 ~]# kubectl get deploy -n ns-test NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE s1 2 2 2 2 10s [root@tvm-00 ~]# kubectl -n ns-dev describe deploy -l run=s1 |grep Image Image: opera443399/whoami:0.9 [root@tvm-00 ~]# kubectl -n ns-test describe deploy -l run=s1 |grep Image Image: opera443399/whoami:0.7 [root@tvm-00 ~]# kubectl -n ns-dev expose deployments/s1 --type="NodePort" --port 80 service "s1" exposed [root@tvm-00 ~]# kubectl -n ns-test expose deployments/s1 --type="NodePort" --port 80 service "s1" exposed [root@tvm-00 ~]# kubectl -n ns-dev get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE s1 NodePort 10.97.87.8
80:31176/TCP 28s [root@tvm-00 ~]# kubectl -n ns-test get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE s1 NodePort 10.98.122.214
80:30946/TCP 26s [root@tvm-00 ~]# curl -s tvm-00:31176 |grep version [howto] version: 0.9 [root@tvm-00 ~]# curl -s tvm-00:30946 |grep version [howto] version: 0.7

转载地址:http://uveso.baihongyu.com/

你可能感兴趣的文章
传RIM意将手机业务剥离出来独立上市或甚至将其出售
查看>>
分页静态化处理
查看>>
JS实现动态显示当前时间
查看>>
ip policy route-map在VLAN上不能应用的解决办法-SDM_quanshengaa-ChinaUnix博客
查看>>
linux 计划任务习题
查看>>
asm示例
查看>>
Web.py HelloWorld与中文乱码
查看>>
表单验证提示插件validate
查看>>
C语言中extern关键字用法
查看>>
Centos7的安装及基本优化
查看>>
我的友情链接
查看>>
企业数据备份流程
查看>>
JNI之C++调用Java类
查看>>
vmware12
查看>>
thinkphp基础学习简单条件查询
查看>>
XenApp / XenDesktop 7.6 初体验六 Remote PC Access
查看>>
Django CSRF 简述
查看>>
翻编-JavaScript有关的10个怪癖和秘密
查看>>
Discuz!X论坛开发(五)二次开发 教你识别程序目录和文件列表for discuzx!1--NO.4
查看>>
Swift编写的一些完整的app
查看>>