Join my course at Udemy (Python Programming Bible-From beginner to advanced )

Blogger templates

Tuesday 17 September 2024

Kubernetes - Namespace

Kubernetes - Namespace

Default namespace created by Kubernetes 

  • kube-system
  • kube-public
  • default

How it is helpful ?

  • These different namespace 
    • can be used by same cluster for DEV and PROD environment.
    • they will have isolated resources between them so that DEV will have their own resource and PROD will have their own resource.
    • they will have their own policies that define who can do what
      • Each namespace has a max limit of resources and are not allowed to use more than its allowed limit. 
      • We can define policy such that for example, while working in DEV environment, we can't modify a resource of PRODUCTION.

Example usage of custom namespace. 

  • Dev
  • Test
  • Prod

How to name resources of a namespace?

  • Same namespace 
    • Resources in same namespace ca access via db-service
  • Different namespace
    • Resources in other namespace can access resources in other namespace via ( say DEV resources via - db-service.dev.svc.cluster.local 

Name details

db-service.dev.svc.cluster.local 
  • db-service - Name of the service
  • dev - namespace
  • svc - service
  • cluster.local - domain.
How to create Namspace Or Pod Inside Namespace
  • Create in default namespace
    • kubectl create -f pod-definition.yml -f
  • Create a particular namespace
    • kubectl create -f pod-definition --namespace dev
    • kubectl create -f pod-definition -n dev
  • Create a Namespace
    • kubectl create -f namespace-dev.yaml
    • kubectl create namespace dev
    • Sample Yaml file for Namespace
      • apiVersion: v1
      • kind: Namespace
      • metadata:
        • name: dev
  • Create POD under a namespace through Yaml file
    • apiVersion: v1
    • kind: Pod
    • metadata
      • name: myapp-pod
      • namespace: dev
      • label
        • app: myapp
        • type: front-end
      • spec
        • container:
          • name: nginx-container
          • image: nbinx
  • Accessing Namespace
    • Scenario -1 : Access default namespace
      • kubectl get pods 
      • kubectl get pods --namespace dev
      • kubectl get pods --namespace prod
  • Change the default namespace to namespace = dev
    • kubectl config set-context  $(kubectl config current-context) --namespace dev
    • kubectl get pods  <<<< This will show Pods from namespace = DEV.
    • kubectl get pods --namespace default << To access default namespace
    • kubectl get pods --namespace prod << To access PROD namespace
  • Resource Quota
    • Resources can be limited in a namespace.
      • apiVersion: v1
      • kind: ResourceQuota
      • metadata:
        • name: compute-quota
        • namespace: dev
      • spec:
        • hard:
          • pods: "10",
          • requests-cpu: "4"
          • requests-memory: 5Gi
          • limts-cpu: "10"
          • limits-memory: 10Gi









Share:

Thursday 12 September 2024

Kubernetes- Deployment

Kubernetes- Deployment

- Defines how to deploy application in production environment.

Scenarios
  • Old instance running - Multiple Pod having applications are running in production environment.
  • New version of application is available - need to upgrade seamlessly- without any downtime.
    • Rolling update
      • For this we don't want to upgrade all of them at once as this may impact accessibility. 
      • One by one upgrade - And we might want to upgrade one after other.
    • In case of failure - we should be able to rollback the upgrade.
    • Multiple change to environment
      • Ex - Scaling the environment, Modifying resource allocation etc.
      • And this change should be done for all PODS together and then activated for all Pods as the same time.

Kubernetes Deployment

  • Comes at the top of the hierarchy.
    • Comes at top of Pod and Replica Set.
  • Available with
    • Rolling update
    • Undo changes
    • Pause changes
    • Resume changes

How to create deployment

Yaml file 

  • same as ReplicaSet except for change in KIND.


apiVersionapps/v1   
kind: Deployment      << Only change done for Deployment

metadata:
  name: myapp-replicaset
  labels:
    app: myapp
    type: front-end

spec:
  template:   <<< Here need to provide template for POD. We just to insert metadata + spec section of POD.
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        type: front-end
    
    spec:   
      containers: 
        name: nginx-container
        image: nginx
  replicas: 3   <<< This is sibling of template
  selector:        
    matchLabels:
      type: front-end

Commands
















Share:

Feature Top (Full Width)

Pageviews

Search This Blog