1,Namespace在很多情况下用于实现多用户的资源隔离,通过将集群内部的资源对象分配到不同的Namespace中,形成逻辑上的分组,便于不同的分组在共享使用整个集群的资源同时还能被分别管理。
[root@bigserver3 ~]# kubectl create namespace tanktest //命令插入 namespace/tanktest created [root@bigserver3 ~]# cat tanktest.yaml //创建创建文件 apiVersion: v1 kind: Namespace metadata: name: tanktest1 [root@bigserver3 ~]# kubectl create -f tanktest.yaml //通过文件创建 namespace/tanktest1 created [root@bigserver3 ~]# kubectl get ns //查看namespace NAME STATUS AGE default Active 11d elk Active 21h kube-node-lease Active 11d kube-public Active 11d kube-system Active 11d kubernetes-dashboard Active 10d tanktest Active 80s tanktest1 Active 18s [root@bigserver3 ~]# kubectl replace --force -f tanktest.yaml //重建 namespace "tanktest1" deleted namespace/tanktest1 replaced [root@bigserver3 ~]# kubectl delete namespaces tanktest //删除 namespace "tanktest" deleted
2,Label是Kubernetes系统中另一个核心概念。一个Label是一个key=value的键值对,其中key与value由用户自己指定。
[root@bigserver3 ~]# kubectl label nodes testing tank=test //创建label node/testing labeled [root@bigserver3 ~]# kubectl label nodes testing tank=123 --overwrite //重新设置label node/testing labeled [root@bigserver3 ~]# kubectl get nodes --show-labels |grep tank //查看 [root@bigserver3 ~]# kubectl label nodes testing tank- //删除,注意-号
3,Deployment是Kubenetes v1.2引入的新概念,引入的目的是为了更好的解决Pod的编排问题,Deployment内部使用了Replica Set来实现。Deployment的定义与Replica Set的定义很类似,除了API声明与Kind类型有所区别
[root@bigserver3 elk]# kubectl create -f elk-deployment.yaml //创建deployment deployment.apps/elk-deployment created [root@bigserver3 ~]# kubectl delete deployment elk-deployment -n elk //删除 deployment.apps "elk-deployment" deleted [root@bigserver3 elk]# kubectl replace --force -f elk-deployment.yaml //重建 deployment.apps "elk-deployment" deleted deployment.apps/elk-deployment replaced [root@bigserver3 ~]# kubectl get deployment -n elk //查看 NAME READY UP-TO-DATE AVAILABLE AGE elk 1/1 1 1 21h [root@bigserver3 ~]# kubectl get deployments --all-namespaces //查看所有 NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE default nginx 1/1 1 1 10d elk elk 1/1 1 1 21h kube-system coredns 2/2 2 2 11d kubernetes-dashboard dashboard-metrics-scraper 1/1 1 1 10d kubernetes-dashboard kubernetes-dashboard 1/1 1 1 10d
4,Service是Kubernetes最核心概念,通过创建Service,可以为一组具有相同功能的容器应用提供一个统一的入口地址,并且将请求负载分发到后端的各个容器应用上。
[root@bigserver3 elk]# kubectl create -f elk-elastic.yaml //创建 service/elk-elastic created [root@bigserver3 elk]# kubectl replace --force -f elk-elastic.yaml //重建 service/elk-elastic replaced [root@bigserver3 ~]# kubectl get svc -n elk //查看 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE elk-elastic ClusterIP 10.1.40.47 9200/TCP 21h elk-kibana NodePort 10.1.7.179 5601:30009/TCP 21h elk-logstash ClusterIP 10.1.166.240 5044/TCP 21h [root@bigserver3 elk]# kubectl delete svc elk-elastic -n elk //删除 service "elk-elastic" deleted
5,Pod是Kubernetes的最重要概念,每一个Pod都有一个特殊的被称为”根容器“的Pause容器。Pause容器对应的镜像属于Kubernetes平台的一部分,除了Pause容器,每个Pod还包含一个或多个紧密相关的用户业务容器。
# kubectl create -f ./pod.json //通过pod.json文件创建一个pod。 # kubectl delete -f ./pod.json //使用 pod.json中指定的资源类型和名称删除pod。 # kubectl delete pod,service test //删除名为test的Pod和Service。 # kubectl delete pods,svc -l name=tank //删除 Label name=tank的pod和Service。 # kubectl delete pod foo --grace-period=0 --force //强制删除dead node上的pod # kubectl delete pods --all //删除所有pod //通过设置replicas来删除pod [root@bigserver3 mysql]# kubectl scale --replicas=0 -f mysql-rc.yaml replicationcontroller/mysql scaled [root@bigserver3 mysql]# kubectl get pod NAME READY STATUS RESTARTS AGE mysql-cd7tm 1/1 Terminating 0 57s nginx-f89759699-545w5 1/1 Running 0 10d [root@bigserver3 mysql]# kubectl get pod NAME READY STATUS RESTARTS AGE nginx-f89759699-545w5 1/1 Running 0 10d # kubectl replace -f ./pod.json //通过pod.json文件重建pod # kubectl replace --force -f ./pod.json //通过pod.json文件强制重建 //查看所有pod,svc [root@bigserver3 ~]# kubectl get pod,svc --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE default pod/nginx-f89759699-545w5 1/1 Running 0 11d elk pod/elk-ddc4c865b-859ks 1/1 Running 0 22h kube-system pod/coredns-7ff77c879f-bxgtr 1/1 Running 2 11d kube-system pod/coredns-7ff77c879f-t4vm9 1/1 Running 2 11d kube-system pod/etcd-bigserver3 1/1 Running 3 11d kube-system pod/kube-apiserver-bigserver3 1/1 Running 3 11d kube-system pod/kube-controller-manager-bigserver3 1/1 Running 3 11d kube-system pod/kube-flannel-ds-amd64-4p9x4 1/1 Running 1 10d kube-system pod/kube-flannel-ds-amd64-772tm 1/1 Running 0 11d kube-system pod/kube-flannel-ds-amd64-d75d5 1/1 Running 1 11d kube-system pod/kube-proxy-846sd 1/1 Running 0 10d kube-system pod/kube-proxy-8mpj4 1/1 Running 0 11d kube-system pod/kube-proxy-dmsq4 1/1 Running 2 11d kube-system pod/kube-scheduler-bigserver3 1/1 Running 2 11d kubernetes-dashboard pod/dashboard-metrics-scraper-6b4884c9d5-kdqvp 1/1 Running 0 10d kubernetes-dashboard pod/kubernetes-dashboard-7b544877d5-gz6h5 1/1 Running 1 10d NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default service/kubernetes ClusterIP 10.1.0.1 443/TCP 11d default service/nginx NodePort 10.1.54.199 80:30412/TCP 11d elk service/elk-elastic ClusterIP 10.1.40.47 9200/TCP 22h elk service/elk-kibana NodePort 10.1.7.179 5601:30009/TCP 22h elk service/elk-logstash ClusterIP 10.1.166.240 5044/TCP 22h kube-system service/kube-dns ClusterIP 10.1.0.10 53/UDP,53/TCP,9153/TCP 11d kubernetes-dashboard service/dashboard-metrics-scraper ClusterIP 10.1.66.50 8000/TCP 10d kubernetes-dashboard service/kubernetes-dashboard NodePort 10.1.25.76 443:30001/TCP 10d
转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/cloud/2413.html
最近也在研究k8s,还是感觉过于庞大,不适于中小型企业。