kubernetes

20210827 (금) 컨트롤러 활용

gusalstm 2021. 8. 27. 16:46
반응형
vagrant@kube-control1:~/work/20210827$ kubectl api-resources
NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND
bindings                                                                      true         Binding
componentstatuses                 cs                                          false        ComponentStatus
configmaps                        cm                                          true         ConfigMap
endpoints                         ep                                          true         Endpoints
events                            ev                                          true         Event
limitranges                       limits                                      true         LimitRange
namespaces                        ns                                          false        Namespace
nodes                             no                                          false        Node
persistentvolumeclaims            pvc                                         true         PersistentVolumeClaim
persistentvolumes                 pv                                          false        PersistentVolume
pods                              po                                          true         Pod
podtemplates                                                                  true         PodTemplate
replicationcontrollers            rc                                          true         ReplicationController
resourcequotas                    quota                                       true         ResourceQuota
secrets                                                                       true         Secret
serviceaccounts                   sa                                          true         ServiceAccount
services                          svc                                         true         Service
mutatingwebhookconfigurations                  admissionregistration.k8s.io   false        MutatingWebhookConfiguration
validatingwebhookconfigurations                admissionregistration.k8s.io   false        ValidatingWebhookConfiguration
customresourcedefinitions         crd,crds     apiextensions.k8s.io           false        CustomResourceDefinition
apiservices                                    apiregistration.k8s.io         false        APIService
controllerrevisions                            apps                           true         ControllerRevision
daemonsets                        ds           apps                           true         DaemonSet
deployments                       deploy       apps                           true         Deployment
replicasets                       rs           apps                           true         ReplicaSet
statefulsets                      sts          apps                           true         StatefulSet
tokenreviews                                   authentication.k8s.io          false        TokenReview
localsubjectaccessreviews                      authorization.k8s.io           true         LocalSubjectAccessReview
selfsubjectaccessreviews                       authorization.k8s.io           false        SelfSubjectAccessReview
selfsubjectrulesreviews                        authorization.k8s.io           false        SelfSubjectRulesReview
subjectaccessreviews                           authorization.k8s.io           false        SubjectAccessReview
horizontalpodautoscalers          hpa          autoscaling                    true         HorizontalPodAutoscaler
cronjobs                          cj           batch                          true         CronJob
jobs                                           batch                          true         Job
certificatesigningrequests        csr          certificates.k8s.io            false        CertificateSigningRequest
leases                                         coordination.k8s.io            true         Lease
bgpconfigurations                              crd.projectcalico.org          false        BGPConfiguration
bgppeers                                       crd.projectcalico.org          false        BGPPeer
blockaffinities                                crd.projectcalico.org          false        BlockAffinity
clusterinformations                            crd.projectcalico.org          false        ClusterInformation
felixconfigurations                            crd.projectcalico.org          false        FelixConfiguration
globalnetworkpolicies                          crd.projectcalico.org          false        GlobalNetworkPolicy
globalnetworksets                              crd.projectcalico.org          false        GlobalNetworkSet
hostendpoints                                  crd.projectcalico.org          false        HostEndpoint
ipamblocks                                     crd.projectcalico.org          false        IPAMBlock
ipamconfigs                                    crd.projectcalico.org          false        IPAMConfig
ipamhandles                                    crd.projectcalico.org          false        IPAMHandle
ippools                                        crd.projectcalico.org          false        IPPool
kubecontrollersconfigurations                  crd.projectcalico.org          false        KubeControllersConfiguration
networkpolicies                                crd.projectcalico.org          true         NetworkPolicy
networksets                                    crd.projectcalico.org          true         NetworkSet
endpointslices                                 discovery.k8s.io               true         EndpointSlice
events                            ev           events.k8s.io                  true         Event
ingresses                         ing          extensions                     true         Ingress
ingressclasses                                 networking.k8s.io              false        IngressClass
ingresses                         ing          networking.k8s.io              true         Ingress
networkpolicies                   netpol       networking.k8s.io              true         NetworkPolicy
runtimeclasses                                 node.k8s.io                    false        RuntimeClass
poddisruptionbudgets              pdb          policy                         true         PodDisruptionBudget
podsecuritypolicies               psp          policy                         false        PodSecurityPolicy
clusterrolebindings                            rbac.authorization.k8s.io      false        ClusterRoleBinding
clusterroles                                   rbac.authorization.k8s.io      false        ClusterRole
rolebindings                                   rbac.authorization.k8s.io      true         RoleBinding
roles                                          rbac.authorization.k8s.io      true         Role
priorityclasses                   pc           scheduling.k8s.io              false        PriorityClass
csidrivers                                     storage.k8s.io                 false        CSIDriver
csinodes                                       storage.k8s.io                 false        CSINode
storageclasses                    sc           storage.k8s.io                 false        StorageClass
volumeattachments                              storage.k8s.io                 false        VolumeAttachment

 

 Controller 

   pod를 정상적으로 동작시키기 위하여 특정 상태를 보장하는 역할을 수행하는 오브젝트

 1) ReplicationController

    pod가 일정 개수만큼 복제되어 동작하는 것을 보장하는 컨트롤러 

    - 구성에 필요한 요소 : Pod를 지정하기 위한 Label selector
         새로운 pod의 복제본을 생성하기 위한 pod의 template
         실행시킬 pod 복제본 갯수 replicas

    - Replication Controller 의 Pod Scaling

         kubectl scale replicationcontrollers REPLICATION_CONTROLLER --replicas N

    - etcd에 저장된 replicationcontrollers의 편집

         kubectl edit replicationcontrollers REPLICATION_CONTROLLER

         replicas 편집시 즉시 desire수정되어서 개수에 맞게 복제/삭제 

 2) Replicaset

     Replication controller와 같이 일정 개수의 pod 동작을 보장하는 컨트롤러

     Replication controller가 일치성 기반의 label selector만을 지원했던 것과 달리 집합성 기준의 label selector 지원

     - ReplicaSet의 Label Selector

       matchLabels:  / key: value 형태로 매니페스트 파일에 작성

     - matchExpressions 집합성 기반의 Label Selector

       key: 선택한 레이블의 키 이름 지정

       values: 선택한 레이블의 값 지정

       operator: 연산자 

         - In: label의 키와 값이 지정된 범위안에 존재하는 경우

         - NotIn: label의 키와 값이 지정된 범위안에 존재하지 않는 경우

         - Exists: label의 키가 포함되어야 함

         - DoesNotExists: label의 키가 포함되지 않음

 3) Daemonset

     노드 레이블 지정 시 노드 레이블이 매치되는 모든 노드에 pod를 한개씩 배치함

     별도의 노드 레이블을 지정하지 않은 경우에는 Cluster의 모든 노드에 pod를 한개씩 배치함      

     ReplicationController 및 ReplicaSet과 유사하지만 별도로 복제본의 갯수를 지정하지 않음

     Cluster에 노드가 추가되는 경우 자동으로 pod를 배치함.

     → node에 selector와 일치하는 label을 작성하면 pod가 자동으로 생성됨

 

 4) Job

     pod의 애플리케이션이 실행되고 정상적으로 종료되는 것에 초점이 맞춰진 컨트롤러

     pod의 애플리케이션의 실행을 마치고 나면 pod는 정상 종료됨

 

 5) Cron Job

     pod의 애플리케이션이 주기적으로 실행되도록 하는 컨트롤러

     

 

vagrant@kube-control1:~/work/20210827$ cat myapp-job-parallel.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: myapp-job-parallel
spec:
  completions: 3
  parallelism: 3
  template:
    metadata:
      labels:
        app: myapp-job-parallel
    spec:
      restartPolicy: OnFailure
      containers:
      - name: myapp
        image: titiiscat/busybox:uploadtest
        command: ["sleep", "90"]

vagrant@kube-control1:~/work/20210827$ cat myapp-rs-matchexpressions2.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp-rs-matchexp2
spec:
  replicas: 4
  selector:
    matchExpressions:
    - key: env
      operator: Exists
    - key: app
      operator: In
      values:
      - myapp-rs-matchexp2
  template:
    metadata:
      labels:
        env: develop
        app: myapp-rs-matchexp2
    spec:
      containers:
      - name: myapp
        image: devops2341/go-myweb:latest
        ports:
        - containerPort: 8080
          protocol: TCP
vagrant@kube-control1:~/work/202108

 

 

 

728x90