01 - Core Concepts - Namespaces

Namespaces

$ kubectl get namespaces                    
$ kubectl get ns                                  
$ kubectl get ns --no-headers | wc -l   
Look for existing Namespaces.

$ kubectl get pods --all-namespaces           
$ kubectl get pods -A                                 

$ kubectl get pods -o wide -A                                  
$ kubectl get pods -o wide -A | grep <xxx-name>      


Q: How many pods exist in the research namespace?
$ kubectl get pods --namespace=<namespace-name>                      
$ kubectl get pods -n <namespace-name>                                       
$ kubectl get pods -n <namespace-name> --no-headers | wc -l        


$ kubectl run <name> --image <image-name> -n <namespace-name>         

$ kubectl describe pod <pod-name> -n <namespace-name>                        


$ kubectl create namespace <namespace-name>      
$ kubectl create ns 
<namespace-name>                   
Create a new namespace.


Access a service that is in a different namespace

$ kubectl get svc -n=<namespace-name>                        

྿ 同一個 namespace(e.g. marketing)中的 services,可以通過名稱來 access 另一個 service(e.g. db-service)。
  • Since the blue application and the db-service are in the same namespace, we can simply use the service name (db-service) to access the database.



྿ 不同 namespace 中的 services,必須使用包含 namespace 的完整地址,才可 access 另一個 namespace 中的 service。
  • e.g. `marketing` namespace 中的 `blue` application service,若想要 access `dev` namespace 中的 `db-service` service,其完整地址為 'db-service.dev.svc.cluster.local'。
  • Since the blue application and the db-service are in different namespaces. In this case, we need to use the service name along with the namespace to access the database. 
    • The FQDN (fully Qualified Domain Name) for the db-service in this example would be db-service.dev.svc.cluster.local.
    • You can also access it using the service name and namespace like this: db-service.dev.




留言