This is the 10th day of my participation in Gwen Challenge

7 Controller Configuration List

7.1 ReplicaSet Controller

See Kubectl Explain Replicaset for details

  • List the specification
apiVersion	<string>    API version number, usually apps/v1
kind	    <string>    What type of resource does the tag create
metadata    <Object>    # POD metadata
spec	    <Object>    # metadata
Copy the code

7.1.1 replicaset. Spec specification

  1. Replicas Specifies the number of replicas

  2. The selector tag selector, which can use two types of selector matchLabels and matchExpressions to select the target POD

MatchExpressions: matchExpressions are defined based on a given expression using the tag selector: {key:"KEY",operator:"OPERATOR",value:[VAL1,VAL2,...] } Use key and value to perform operator operations, and compound conditions are selected only when operators: In, NotIn: their value list must have a value Exists, NotExists: their value must be emptyCopy the code
  1. The template template defines a POD object that contains only two parts: pod.metadata and pod.spec.

7.1.2 Sample Listing

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myrs
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
      release: canary
  template:
    metadata:
      name: myapp-pod     This is useless because the POD created starts with the name RS
      labels:
        app: myapp        Tags must conform to replicaset's tag selector rules, otherwise they will fall into an endless loop of creating pods until resources run out
        release: canary
    spec:
      containers:
        - name: myapp-containers
          image: ikubernetes/myapp:v1
          ports:
            - name: http
              containerPort: 80
Copy the code

7.2 Deployment Controller

Deployment implements its functions by controlling ReplicaSet. Besides scale-up of ReplicaSet, Deployment also supports rolling update and rollback, etc. It also provides declarative configuration, which is the most commonly used controller in our daily life. It is used to manage stateless applications.

Deployment implements rolling updates by controlling multiple Replicasets, which in turn control multiple PODS. Multiple Replicasets are equivalent to multiple application versions.

graph TB
Deployment[Deployment] --> replicaset1(replicaset1) 
Deployment[Deployment] --> replicaset2(replicaset2)
Deployment[Deployment] --> replicaset3(replicaset3)
replicaset1(replicaset1) --> POD1{POD}
replicaset1(replicaset1) --> POD2{POD}
replicaset2(replicaset1) --> POD5{POD}
replicaset2(replicaset1) --> POD6{POD}
replicaset3(replicaset1) --> POD9{POD}
replicaset3(replicaset1) --> POD10{POD}
  • Listing specification, see kubectl Explain Deployment
apiVersion	<string>    # apps/v1

kind	    <string>    What type of resource does the tag create

metadata    <Object>    # POD metadata

spec	    <Object>    # metadata
Copy the code

7.2.1 Replicaset. spec Object specification

  1. Replicas Specifies the number of replicas

  2. The selector tag selector, which can use two types of selector matchLabels and matchExpressions to select the target POD

MatchExpressions: matchExpressions are defined based on a given expression using the tag selector: {key:"KEY",operator:"OPERATOR",value:[VAL1,VAL2,...] } Use key and value to perform operator operations, and compound conditions are selected only when operators: In, NotIn: their value list must have a value Exists, NotExists: their value must be emptyCopy the code
  1. The template template defines a POD object that contains only two parts: pod.metadata and pod.spec.

  2. Strategy Update policy, which supports rolling update and update modes

type:Update types, concept replacement update, RollingUpdate strategyRollingUpdate:This is the default update policyMaxSurge:You can specify the number or percentage of temporary updates allowed when scrolling. Default is 25%MaxUnavailable:# Maximum number of pods allowed to be unavailable. Default: 25%
Copy the code
  • Abstract: Replace updates delete the old container group first, and while creating a new container group, the upgrade interrupts the business

  • RollingUpdate: the RollingUpdate will gradually replace the instance of the old version with the instance of the new version. During the upgrade, the service traffic will be loaded to the POD of the old version and the POD of the new version. Therefore, the service will not be interrupted.

  1. RevisionHistoryLimit Specifies the maximum number of historical versions that can be saved after scrolling. The value is a number

  2. Paused Controls whether to pause after the update is started

7.2.2 Sample listing

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deploy
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
      release: canary
  template:
    metadata:
      labels:
        app: myapp
        release: canary
    spec:
      containers:
        - name: myapp
          image: ikubernetes/myapp:v1
          ports:
            - name: http
              containerPort: 80
Copy the code

7.2.3 About Updates

  1. Modify the manifest file directly, kubectl apply -f deployment.yaml
  2. Use Kubectl Patch to present the updated content in JSON format
kubectl patch deployment myapp-deploy -p '{"spec":{"replicas":5}}'    # Change the number of POD copies

kubectl patch deployment myapp-deploy -p '{"spec":{"strategy":{"rollingUpdate":{"maxSurge":1,"maxUnavailable":0}}}}'                                 Modify the update policy
Copy the code
  1. Update kubectl set image only
kubectl set image deployment myapp-deploy myapp=ikubernetes/myapp:v3
Copy the code

7.2.4 Analog Canary release

  • When the update is just started, the update process is paused so that only one update can be made, which enables the addition of a canary version to the cluster
kubectl set image deployment myapp-deploy myapp=ikubernetes/myapp:v3 && kubectl rollout pause deployment myapp-deploy
Copy the code
  • Looking at the paused controller status that has been updated, you can see the Deployment that has been suspended
kubectl rollout status deployment myapp-deploy
Copy the code
Waiting for deployment "myapp-deploy"rollout to finish: 1 out of 5 new replicas have been updated... Wait for the deployment"myapp-deploy"Deployment complete: 1 of 5 new replicas updated...Copy the code
  • If there is nothing wrong with canary, then continue can use the continue update command
kubectl rollout resume deployment myapp-deploy
Copy the code

7.2.5 Updating policies

  • The maximum unavailability is 0, and you can temporarily exceed 1 when updating
kubectl patch deployment myapp-deploy -p '{"spec":{"strategy":{"rollingUpdate":{"maxSurge":1,"maxUnavailable":0}}}}'
Copy the code

7.2.6 About Rollback

  1. Rollout undo is the rollback command, which by default rolls back to the previous version
kubectl rollout undo deployment myapp-deploy
Copy the code
  1. View versions that can be rolled back
kubectl rollout history deployment myapp-deploy
Copy the code
  1. Rollout undo Specifies the version to be rolled back
kubectl rollout undo deployment myapp-deploy --to-revision=2
Copy the code
  1. View the current working version
kubectl get rs -o wide
Copy the code

7.3 DaemonSet Controller

  • Listing specification, see Kubectl Explain Daemonset
apiVersion	<string>    # apps/v1

kind	    <string>    What type of resource does the tag create

metadata    <Object>    # POD metadata

spec	    <Object>    # metadata
Copy the code

7.3.1 DaemonSet. Spec specification

Only the differences are listed here

  1. UpdateStrategy Update policy, which supports rolling update and rolling update. By default, each node is updated by rolling update
rollingUpdate   It has a single rollingUpdate parameter that updates DaemonSet tasks on several nodes at a time
OnDelete        # Update when deleted
Copy the code

7.3.2 Sample Listing

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
      role: logstor
  template:
    metadata:
      labels:
        app: redis
        role: logstor
    spec:
      containers:
        - name: redis
          image: Redis: 4.0 - alpine
          ports:
            - name: redis
              containerPort: 6379
---                                         You can use -- to separate multiple records
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: filebeat-daemonset
  namespace: default
spec:
  selector:
    matchLabels:
      app: filebeat
      release: stalbe
  template:
    metadata:
      labels:
        app: filebeat
        release: stalbe
    spec:
      containers:
        - name: filebeat
          image: Ikubernetes/filebeat: 5.6.5 - alpine
          env:                                         Pass environment variables to the container
            - name: REDIS_HOST                         The name of the environment variable inside the container
              value: redis.default.svc.cluster.local   The value of the environment variable points to the Redis service
            - name: REDIS_LOG_LEVEL
              value: info
Copy the code

7.3.3 About Updates

  • Update the image of the Filebeat container under the Daemonset controller
kubectl setImage daemonsets filebeat - daemonset filebeat = ikubernetes/filebeat: 5.6.6 - alpineCopy the code

other

Send your notes to: github.com/redhatxl/aw… Welcome one button three links