美文网首页
2021-04-26周一,拉取镜像升级

2021-04-26周一,拉取镜像升级

作者: 文茶君 | 来源:发表于2021-04-26 22:50 被阅读0次

    先看了下博客
    更新k8s镜像版本的三种方式https://www.jianshu.com/p/a4cedd569899

    kubectl get pods --namespace=kubesphere-logging-system
    获取特定namespace的pod
    kubectl get pods --namespace=kubesphere-logging-system -owide

    kubectl get deploy --all-namespaces
    查看所有namespaces

    修改service的yaml文件
    kubectl edit svc xxxxx

    查看pod日志
    kubectl logs pods/ks-installer-777b895fdb-xlbq6 --namespace="kubesphere-system"

    查看yaml
    kubectl describe pods/ks-installer-777b895fdb-xlbq6 --namespace="kubesphere-system"

    目标:升级fluentbit

     kubectl get deploy --namespace=kubesphere-logging-system -owide
    NAME                         READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS                            IMAGES                                                                   SELECTOR
    fluentbit-operator           1/1     1            1           5d    fluentbit-operator                    kubespheredev/fluentbit-operator:v0.4.0                                  app.kubernetes.io/component=operator,app.kubernetes.io/name=fluentbit-operator
    logsidecar-injector-deploy   2/2     2            2           5d    logsidecar-injector,config-reloader   kubesphere/log-sidecar-injector:1.1,jimmidyson/configmap-reload:v0.3.0   app.kubernetes.io/instance=logsidecar-injector,app.kubernetes.io/managed-by=Helm,app.kubernetes.io/name=logsidecar-injector,app.kubernetes.io/version=0.1.0,helm.sh/chart=logsidecar-injector-0.1.0,logging.kubesphere.io/logsidecar-injector=logsidecar-injector-deploy
    

    查看了部署是fluentbit-operator

    kubectl describe pods/fluentbit-operator-6dd9598886-fkt4h --namespace="kubesphere-logging-system"

    Name:         fluent-bit-4tjlx
    Namespace:    kubesphere-logging-system
    Priority:     0
    Node:         i-f1or71kf/192.168.1.2
    Start Time:   Wed, 21 Apr 2021 10:25:12 +0800
    Labels:       app.kubernetes.io/name=fluent-bit
                  controller-revision-hash=6c754d6b6c
                  pod-template-generation=1
    Annotations:  cni.projectcalico.org/podIP: 10.233.76.135/32
                  cni.projectcalico.org/podIPs: 10.233.76.135/32
    Status:       Running
    IP:           10.233.76.135
    IPs:
      IP:           10.233.76.135
    Controlled By:  DaemonSet/fluent-bit
    Containers:
      fluent-bit:
        Container ID:   docker://867b38424774f899e0120b547540cabb86ce9ff8c3cf165632e11a9af84cae12
        Image:          kubespheredev/fluent-bit:v1.6.9
        Image ID:       docker-pullable://kubespheredev/fluent-bit@sha256:46ae9a17fe2d308c685c1f0278039ad45db1f254e5cb3302176f72bbf2606255
        Port:           2020/TCP
        Host Port:      0/TCP
        State:          Running
          Started:      Sun, 25 Apr 2021 11:11:28 +0800
        Last State:     Terminated
          Reason:       Error
          Exit Code:    1
          Started:      Sat, 24 Apr 2021 10:25:16 +0800
          Finished:     Sat, 24 Apr 2021 23:16:46 +0800
        Ready:          True
        Restart Count:  2
        Environment:    <none>
        Mounts:
          /fluent-bit/config from config (ro)
          /fluent-bit/tail from positions (rw)
          /var/lib/docker/containers from varlibcontainers (ro)
          /var/log/ from varlogs (ro)
          /var/log/journal from systemd (ro)
          /var/run/secrets/kubernetes.io/serviceaccount from fluent-bit-token-wklp7 (ro)
    Conditions:
      Type              Status
      Initialized       True 
      Ready             True 
      ContainersReady   True 
      PodScheduled      True 
    Volumes:
      varlibcontainers:
        Type:          HostPath (bare host directory volume)
        Path:          /var/lib/docker/containers
        HostPathType:  
      config:
        Type:        Secret (a volume populated by a Secret)
        SecretName:  fluent-bit-config
        Optional:    false
      varlogs:
        Type:          HostPath (bare host directory volume)
        Path:          /var/log
        HostPathType:  
      systemd:
        Type:          HostPath (bare host directory volume)
        Path:          /var/log/journal
        HostPathType:  
      positions:
        Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
        Medium:     
        SizeLimit:  <unset>
      fluent-bit-token-wklp7:
        Type:        Secret (a volume populated by a Secret)
        SecretName:  fluent-bit-token-wklp7
        Optional:    false
    QoS Class:       BestEffort
    Node-Selectors:  <none>
    Tolerations:     
                     node.kubernetes.io/disk-pressure:NoSchedule
                     node.kubernetes.io/memory-pressure:NoSchedule
                     node.kubernetes.io/not-ready:NoExecute
                     node.kubernetes.io/pid-pressure:NoSchedule
                     node.kubernetes.io/unreachable:NoExecute
                     node.kubernetes.io/unschedulable:NoSchedule
    Events:          <none>
    
    

    将v1.6.9升级到v1.7.3

    在不中断服务的情况下更新应用

    在某些时候,你最终需要更新已部署的应用,通常都是通过指定新的镜像或镜像标签, 如上面的金丝雀发布的场景中所示。kubectl 支持几种更新操作, 每种更新操作都适用于不同的场景。

    我们将指导你通过 Deployment 如何创建和更新应用。

    假设你正运行的是 1.14.2 版本的 nginx:

    kubectl create deployment my-nginx --image=nginx:1.14.2
    
    
    deployment.apps/my-nginx created
    
    

    要更新到 1.16.1 版本,只需使用我们前面学到的 kubectl 命令将 .spec.template.spec.containers[0].imagenginx:1.14.2 修改为 nginx:1.16.1

    kubectl edit deployment/my-nginx
    
    

    没错,就是这样!Deployment 将在后台逐步更新已经部署的 nginx 应用。 它确保在更新过程中,只有一定数量的旧副本被开闭,并且只有一定基于所需 Pod 数量的新副本被创建。 想要了解更多细节,请参考 Deployment

    但是kubspere中是通过fluent-operator安装fluent的
    使用kubectl get deployment --all-namespaces -owide只显示fluent-operator

    执行kubectl edit deployment/fluentbit-operator --namespace kubesphere-logging-system
    并无相关配置
    查看部署
    kubectl get deployment --namespace kubesphere-logging-system

    NAME                         READY   UP-TO-DATE   AVAILABLE   AGE
    fluentbit-operator           1/1     1            1           5d4h
    logsidecar-injector-deploy   2/2     2            2           5d4h
    
    
    kubectl get deploy -A | grep fluentbit
    
    kubesphere-logging-system      fluentbit-operator                1/1     1            1           5d4h
    

    查看守护进程

    kubectl get ds -A | grep fluent
    kubesphere-logging-system      fluent-bit      1         1         1       1            1           <none>                        5d4h
    

    修改

    kubectl edit ds fluent-bit -n kubesphere-logging-system
    
    kind: FluentBit
    metadata:
      annotations:
        kubectl.kubernetes.io/last-applied-configuration: |
      creationTimestamp: "2021-04-21T02:14:40Z"
      finalizers:
      - fluentbit.logging.kubesphere.io
      generation: 2
      labels:
        app.kubernetes.io/name: fluent-bit
      name: fluent-bit
      namespace: kubesphere-logging-system
      resourceVersion: "27599"
      selfLink: /apis/logging.kubesphere.io/v1alpha2/namespaces/kubesphere-logging-system/fluentbits/fluent-bit
      uid: adbe3966-523a-4d73-b4b1-06b33a07bf12
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: node-role.kubernetes.io/edge
                operator: DoesNotExist
      fluentBitConfigName: fluent-bit-config
      image: kubespheredev/fluent-bit:v1.6.9
      positionDB:
        emptyDir: {}
      resources: {}
      tolerations:
      - operator: Exists
    

    把1.6.9改成1.7.3

    修改完毕,看成果

     kubectl describe ds fluent-bit -n kubesphere-logging-system
    Name:           fluent-bit
    Selector:       app.kubernetes.io/name=fluent-bit
    Node-Selector:  <none>
    Labels:         app.kubernetes.io/name=fluent-bit
    Annotations:    deprecated.daemonset.template.generation: 3
    Desired Number of Nodes Scheduled: 1
    Current Number of Nodes Scheduled: 1
    Number of Nodes Scheduled with Up-to-date Pods: 1
    Number of Nodes Scheduled with Available Pods: 1
    Number of Nodes Misscheduled: 0
    Pods Status:  1 Running / 0 Waiting / 0 Succeeded / 0 Failed
    Pod Template:
      Labels:           app.kubernetes.io/name=fluent-bit
      Service Account:  fluent-bit
      Containers:
       fluent-bit:
        Image:        kubespheredev/fluent-bit:v1.6.9
        Port:         2020/TCP
        Host Port:    0/TCP
        Environment:  <none>
        Mounts:
          /fluent-bit/config from config (ro)
          /fluent-bit/tail from positions (rw)
          /var/lib/docker/containers from varlibcontainers (ro)
          /var/log/ from varlogs (ro)
          /var/log/journal from systemd (ro)
      Volumes:
       varlibcontainers:
        Type:          HostPath (bare host directory volume)
        Path:          /var/lib/docker/containers
        HostPathType:  
       config:
        Type:        Secret (a volume populated by a Secret)
        SecretName:  fluent-bit-config
        Optional:    false
       varlogs:
        Type:          HostPath (bare host directory volume)
        Path:          /var/log
        HostPathType:  
       systemd:
        Type:          HostPath (bare host directory volume)
        Path:          /var/log/journal
        HostPathType:  
       positions:
        Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
        Medium:     
        SizeLimit:  <unset>
    Events:
      Type    Reason            Age   From                  Message
      ----    ------            ----  ----                  -------
      Normal  SuccessfulDelete  10s   daemonset-controller  Deleted pod: fluent-bit-4tjlx
      Normal  SuccessfulCreate  5s    daemonset-controller  Created pod: fluent-bit-86tdm
    root@i-f1or71kf:~# kubectl get pod -
    Error from server (NotFound): pods "-" not found
    root@i-f1or71kf:~# kubectl get pod -A | grep fluent
    kubesphere-logging-system      fluent-bit-86tdm                                                  1/1     Running     0          32s
    kubesphere-logging-system      fluentbit-operator-6dd9598886-fkt4h    
    
    

    这是没成功,这是因为fluent-operator一直监控着fluent,代码如下:

    // Deploy Fluent Bit DaemonSet
        logPath := r.getContainerLogPath(fb)
        ds := operator.MakeDaemonSet(fb, logPath)
        if err := ctrl.SetControllerReference(&fb, &ds, r.Scheme); err != nil {
            return ctrl.Result{}, err
        }
    
        if _, err := controllerutil.CreateOrUpdate(ctx, r.Client, &ds, r.mutate(&ds, fb)); err != nil {
            return ctrl.Result{}, err
        }
    
        return ctrl.Result{}, nil
    

    通过CRD来修改

    kubectl edit fluentbits.logging.kubesphere.io -n kubesphere-logging-system fluent-bit
    

    即可修改完成
    查看修改结果

    kubectl describe pods/fluent-bit-tql26 --namespace=kubesphere-logging-system
    

    结果显示已修改

    另外也可以通过这种方式升级
    如何拉取k8s镜像 https://www.jianshu.com/p/eca4154fe60b

    相关文章

      网友评论

          本文标题:2021-04-26周一,拉取镜像升级

          本文链接:https://www.haomeiwen.com/subject/azmsrltx.html