Tuesday, January 26, 2021

Kubernetes - ReplicaSet - Day 9

 Kubernetes - ReplicaSet - 1 26- 2021
k8s
- POD -> Launch using yaml ( or Deployment, --> RC -> RS)

Deployment is a great way to manage PODs
- privides different strategy
  - rampd
  - rolling update

App  ->


-----------------------------------------------------
main function of kubernetes is to manage PODs.

apiVersion: v1
kind: Pod
metadata:
  name: "webprod1"
  labels:
    app: frontend
    team: team1
    region: US
    env: prod

spec:
  containers:
  - name: "webc1"
    image: "vimal13/webserver-apache-php"



Resource
- RC (replication controller)
- SVC (service)


Deploy
- RC
  - label (app=myserv)
- Selector (Keep on searching for particular label or ip ..)


selector (way to Search other resources like program rc, POD)
- Equality based selector [Older way]
- Set-Based selector [ Newer way to manage]

when you launch a resource, it is always good practice go give tag or label.




> kc applyu -f pod.basic
> kc get pods --show-labels
> kc get pods -l "env=prod"

> kc get pods --show-labels -l "env=prod"
> kc get pods -show-labels -l "team=team2"
> kc get pods --show-labels -l "team!=team2"
> kc get pods --show-labels --selector "team!=team2"

when you use =, =! == is called equality based selector

we have on challange on this selector

> kc get pods --show-labels


Set based selector - human readable

show all the pods based on region us

> kc get pods --show-labels --selector "relion in (IN,US), team in (team2)"

#  kc get pods --show-labels --selector "region notin (IN,US), team in (team2,team1)"


Launch replica set - Manag replicas of the POD


apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myweb-rs
  labels:
 
spec:
  replicas: 3
  selector:
    matchLabels:
      env=prod

template:
  metadata:
    name: "webprod1"
    labels:
      app: frontend
      team: team1
      region: US
      env: prod

  spec:
    containers:
    - name: "webc1"
      image: "vimal13/webserver-apache-php"




match label -> equality based
match expression - set based  with lots of search options


kc apply -f myweb-rs
kc describe rs myweb-rs




Only supports on RS

spec:
  replicas: 3
  selector:
  matchLabels:
    env: prod
  matchExpressions:
    - { key: team, operator: In, values: [ team1, team2 ]}
    - { key: tier, operator: In, values: [ frontend ] }
  template:
    metadata:
      name: "webpod4"
      labels:
        env: prod
        team: team1
        tier: frontend

    spec:
      containers:
      - name: "webc1"
        image: "vimal13/webserver-apache-php"



> kc create deployment mydep --image=httpd



[root@master jan26]# more mydeploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myweb-deploy

spec:
#  type: recreate
  replicas: 3
  selector:
    matchLabels:
      env: prod
    matchExpressions:
      - { key: team, operator: In, values: [ team1, team2 ]}
      - { key: tier, operator: In, values: [ frontend ] }
  template:
    metadata:
      name: "webpod4"
      labels:
        env: prod
        team: team1
        tier: frontend

    spec:
      containers:
      - name: "webc1"
        image: "vimal13/webserver-apache-php"


default type - rolling update

,..
in python,
>>> name =['a', 'b','a']
>>> 'd' in name
>>> 'a' in name

same concept applies here as well for match expression:-

posuming/resuming

canary strategy



  737  mkdir jan26
  738  cd jan26/
  739  vi mypod.yaml
  740  kc apply -f mypod.yaml
  741  vi mypod.yaml
  742  kc apply -f mypod.yaml
  743  kc get pods
  744  ping yahoo.com
  745  kc get pods --show-labels
  746  kc get pods --show-labels --selector "team!=team2"
  747  vi mypod.yaml
  748  kc apply -f mypod.yaml
  749  kc get pods
  750  kc get pods --show-labels -l "env=prod"
  751  kc get pods --show-labels --selector "relion in (US)"
  752  kc get pods --show-labels --selector "relion in (IN)"
  753  kc get pods --show-labels --selector "relion in (IN,US), team in (team2)"
  754   kc get pods --show-labels --selector "region notin (IN,US, team in (team2,team1)"
  755  kc get pods --show-labels --selector "region notin (IN,US), team in (team2,team1)"
  756  kc delete all --all
  757  vi myreplicaset.yaml
  758  kc get rs
  759  kc get rc
  760  kc apply -f myreplicaset.yaml
  761  vi myreplicaset.yaml
  762  kc apply -f myreplicaset.yaml
  763  vi myreplicaset.yaml
  764  kc apply -f myreplicaset.yaml
  765  kc create deployment mydep --image=httpd
  766  kc get deploy
  767  kc get rs
  768  ke get pod
  769  ke get pods
  770  kc get pods
  771  kc get rs --show-labels
  772  kc describe deplpy mydep
  773  kc describe deploy mydep
  774  kc get all
  775  kc get pods
  776  kc get rs
  777  kc get pods
  778  kc delete pod mydep*
  779  kc delete pod mydep-5dcf7bcbd6-v6rx9
  780  kc get pod





next class multitanency - namespace
- multiple team wroking, hundred of throusands of pods working.

c1 c2 c3 c4 c5 .........>
Team1 work on container 1 and 2
Team2 work on two region running 2 conainer running on one region and 1 on another.

US - 2 pod running, IND -> 5 pod running all the time..


What is selector, label


No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...