• Two boys, Mark Smith and Mark Williams.
    • In each house, the father addresses their Mark as Mark and the other Mark in the other house as Mark Smith.
  • Houses correspond to Namespaces in Kubernetes.
  • Default namespace is created automatically by Kubernetes when it is first setup.
  • There are some other internal services that are created when Kubernetes first starts.
    • This is called kube-system
  • A third namespace automatically generated by Kubernetes is called kube-public. This is made available to all users.
  • For production clusters, multiple namespaces are important.
  • For example, having a Dev and Production environment and then at the same time isolate the resources between them, create a different namespace for each. One being Dev and the other being Production.
  • Each namespace has a policy to define what can be done.
  • A namespace can have a quota of resources assigned to it.
    • For example CPU, disk usage and so on.
  • The resources in a namespace can refer to each other by their hostnames: web-prod, db-service and web-deployment as examples. This could be in the form of mysql.connect("db-service") as an example.
  • A pod can reach a service in another namespace as well. The namespace has to be appended, as well as the service name. An example is mysql.connect("db-service.dev.svc.cluster.local")
    • When a service is created, a DNS entry is added with the above format.
    • cluster.local is the default domain name of the Kubernetes cluster.
    • svc stands for sub-domain for the service.
    • In the above example, service name is db-service, dev is the namespace, svc is the service and cluster.local is the domain.
  • kubectl get pods only lists the pods of the default namespace.
  • To list pods in another namespace, we run kubectl get pods --namespace=<namespace_here>.
  • To create a pod in another namespace, use kubectl create -f pod-definition.yml --namespace=dev
    • The above can also be performed in the pod-definition.yml file, by adding the namespace option to the pod-definition.yml file: ``` pod-definition.yml apiVersion: v1 kind: Pod

metadata name: myapp-pod labels: app: myapp type: front-end spec: containers:

  • name: nginx-container image: nginx ```
  • The pod is created in the default namespace.
  • To create the pod in another namespace, use the --namespace= option:
    kubectl create -f pod-definition.yml --namespace=<namespace_here>
    
  • Can actually add the namespace definition to the pod-definition.yml file, so you do not need to enter it from the commandline constantly: ``` pod-definition.yml apiVersion: v1 kind: Pod

metadata: name: myapp-pod namespace: dev labels: app: myapp type: front-end spec: containers:

  • name: nginx-container image: nginx ```
  • To create a new namespace, use a yml file. An example is below: ``` namespace-dev.yml

apiVersion: v1 kind: Namespace metadata: name: dev

* Then run the `kubectl` command, such as `kubectl create -f namespace-dev.yml`.
* Else, you can create a namespace without needing the above `yml` file with:

kubectl create namespace

* How to switch to another namespace permanently. We can do that using `kubectl` to set the context of the current `namespace`:

kubectl config set-context $(kubectl config current-context) –namespace=

* Then can see these pods with `kubectl get pods` - no need to specify the namespace.
* To view pods in all namespaces, use `kubectl get pods --all-namespaces`
* `contexts` are used to manage multiple clusters and environments from the same management system.
* To limit resources in a `namespace`, create a Resource Quota. Under `spec`, provide the limits. To create a Resource Quota, see an example `yml` file below:

Compute-quota.yaml

apiVersion: v1 kind: ResourceQuota metadata: name: compute-quota namespace:

spec: hard: pod: “10” requests.cpu: “4” requests.memory: 5Gi limits.cpu: “10” limits.memory: 10Gi ```

  • Then create the file with kubectl create -f compute-quota.yaml

Updated: