其他分享
首页 > 其他分享> > Kubernetes阿里阿里云logtail

Kubernetes阿里阿里云logtail

作者:互联网

本文档基于自建Kubernetes平台使用阿里云logtail日志插件,收集Kubernetes标准输出日志

以下是官方文档链接地址

官方安装logtail:https://help.aliyun.com/document_detail/157317.html

官方通过DaemonSet-控制台方式采集Kubernetes标准输出:https://help.aliyun.com/document_detail/66658.html

如何安装helm:https://helm.sh/docs/intro/install/

以下所有操作都在Kubernetes Master节点上执行

  1. 下载安装脚本,如下
    wget http://logtail-release-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/kubernetes/alicloud-log-k8s-custom-install.sh;chmod 744 ./alicloud-log-k8s-custom-install.sh
  2. 编辑安装脚本,根据环境自定义
    <root@PROD-K8S-CP1 ~># cat alicloud-log-k8s-custom-install.sh 
    #!/bin/bash
    
    if [ $# -le 4 ] ; then
        echo "[Invalid Param], use sudo ./install-k8s-log.sh {your-project-suffix} {regionId} {aliuid} {accessKeyId} {accessKeySecret}"
        exit 1
    fi
    
    # project环境变量,根据自己需求定义,最终在SLS生成的project名称为kubernetes-$1
    project="kubernetes-"$1
    regionId=$2
    aliuid=$3
    accessKeyId=$4
    accessKeySecret=$5
    
    helmPackageUrl="http://logtail-release-$regionId.oss-$regionId.aliyuncs.com/kubernetes/alibaba-cloud-log.tgz"
    wget $helmPackageUrl -O alibaba-cloud-log.tgz
    if [ $? != 0 ]; then
        echo "[FAIL] download alibaba-cloud-log.tgz from $helmPackageUrl failed"
        exit 1
    fi
    
    helmV3=`helm version | grep v3 | wc -l`
    
    if [ $helmV3 -eq 0 ]; then
        echo "install alibaba-log-controller using helm v2 command."
        helm install alibaba-cloud-log.tgz --name alibaba-log-controller \
        --set ProjectName=$project \
        --set RegionId=$regionId \
        --set InstallParam=$regionId"_internet" \
        # 注意与上文的project是一样的
        --set MachineGroupId="kubernetes-"$1 \
        --set Endpoint=$regionId".log.aliyuncs.com" \
        --set AlibabaCloudUserId=":"$aliuid \
        --set AlibabaCloudK8SCluster="false" \
        --set Privileged="true" \
        --set AccessKeyId=$accessKeyId \
        --set AccessKeySecret=$accessKeySecret \
        --set LogtailImage.Repository="registry.$regionId.aliyuncs.com/log-service/logtail" \
        --set ControllerImage.Repository="registry.$regionId.aliyuncs.com/log-service/alibabacloud-log-controller"
    else
        echo "install alibaba-log-controller using helm v3 command."
        helm install alibaba-log-controller alibaba-cloud-log.tgz \
        --set ProjectName=$project \
        --set RegionId=$regionId \
        --set InstallParam=$regionId"_internet" \
        # 注意与上文的project是一样的
        --set MachineGroupId="kubernetes-"$1 \
        --set Endpoint=$regionId".log.aliyuncs.com" \
        --set AlibabaCloudUserId=":"$aliuid \
        --set AlibabaCloudK8SCluster="false" \
        --set Privileged="true" \
        --set AccessKeyId=$accessKeyId \
        --set AccessKeySecret=$accessKeySecret \
        --set LogtailImage.Repository="registry.$regionId.aliyuncs.com/log-service/logtail" \
        --set ControllerImage.Repository="registry.$regionId.aliyuncs.com/log-service/alibabacloud-log-controller"
    fi
    
    installRst=$?
    
    if [ $installRst -eq 0 ]; then
        echo [INFO] your k8s is using project : $project, region : $regionId, aliuid : $aliuid, accessKeyId : $accessKeyId
        echo "[SUCCESS] install helm package : alibaba-log-controller success."
        exit 0
    else
        echo "[FAIL] install helm package failed, errno " $installRst
        exit 0
    fi
  3. 安装helm
  4. 安装alibaba-log-controller,如下
    sh ./alicloud-log-k8s-custom-install.sh {your-project-suffix} {region-id} {aliuid} {access-key-id} {access-key-secret}
    具体带入的参数解释请参考官方文档
    https://help.aliyun.com/document_detail/157317.html?spm=a2c4g.11186623.6.622.37f27cdfTStC5F#title-7qc-o6x-x8f
     
     
    具体最终执行命令如下:
    sh ./alicloud-log-k8s-custom-install.sh non-production cn-hangzhou 1358359200279133 LTAI4FqfAcMq2fUts7kpP7VK SK(根据自己申请的SK填充)
    
    <root@PROD-K8S-CP1 ~># sh ./alicloud-log-k8s-custom-install.sh prod cn-hangzhou aliuid LTAI4FqfAcMq2fUts7kpP7VK SK
    --2021-08-31 17:14:53--  http://logtail-release-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/kubernetes/alibaba-cloud-log.tgz
    Resolving logtail-release-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com (logtail-release-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com)... 47.110.177.113
    Connecting to logtail-release-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com (logtail-release-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com)|47.110.177.113|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 3785 (3.7K) [application/octet-stream]
    Saving to: ‘alibaba-cloud-log.tgz’
    
    100%[========================================================================================================================================================================>] 3,785       --.-K/s   in 0s      
    
    2021-08-31 17:14:53 (419 MB/s) - ‘alibaba-cloud-log.tgz’ saved [3785/3785]
    
    install alibaba-log-controller using helm v3 command.
    NAME: alibaba-log-controller
    LAST DEPLOYED: Tue Aug 31 17:14:53 2021
    NAMESPACE: default
    STATUS: deployed
    REVISION: 1
    TEST SUITE: None
    [INFO] your k8s is using project : kubernetes-prod, region : cn-hangzhou, aliuid : 1358359200279133, accessKeyId : LTAI4FqfAcMq2fUts7kpP7VK
    [SUCCESS] install helm package : alibaba-log-controller success.
  5. 查看helm安装状态
    <root@PROD-K8S-CP1 ~># helm list
    NAME                      NAMESPACE    REVISION    UPDATED                                    STATUS      CHART                      APP VERSION
    alibaba-log-controller    default      1           2021-08-31 17:14:53.415754717 +0800 CST    deployed    alibaba-cloud-log-0.2.3    1.0        
    <root@PROD-K8S-CP1 ~># helm status alibaba-log-controller
    NAME: alibaba-log-controller
    LAST DEPLOYED: Tue Aug 31 17:14:53 2021
    NAMESPACE: default
    STATUS: deployed
    REVISION: 1
    TEST SUITE: None
    
    # 如果在安装过程中遇到问题,可以卸载重新安装
    <root@PROD-K8S-CP1 ~># helm uninstall alibaba-log-controller
    release "alibaba-log-controller" uninstalled、
  6. 查看logtai启动状态
    <root@PROD-K8S-CP1 ~># kubectl get po -n kube-system | grep logtail
    logtail-ds-6b67m                          1/1     Running   0          6m59s
    logtail-ds-6r8bb                          1/1     Running   0          7m13s
    logtail-ds-88w48                          1/1     Running   0          7m28s
    logtail-ds-bsfkx                          1/1     Running   0          9m21s
    logtail-ds-btlrd                          1/1     Running   0          7m44s
    logtail-ds-dwvds                          1/1     Running   0          8m24s
    logtail-ds-dxt9f                          1/1     Running   0          8m16s
    logtail-ds-hjd9w                          1/1     Running   0          8m37s
    logtail-ds-hqcsh                          1/1     Running   0          9m8s
    logtail-ds-j2jt9                          1/1     Running   0          7m7s
    logtail-ds-kmjmv                          1/1     Running   0          8m52s
    logtail-ds-qcwjv                          1/1     Running   0          9m14s
    logtail-ds-r4p55                          1/1     Running   0          8m2s
    logtail-ds-ss52s                          1/1     Running   0          7m56s
    logtail-ds-sxn7d                          1/1     Running   0          8m32s
    logtail-ds-t4hbd                          1/1     Running   0          6m42s
    logtail-ds-txzvt                          1/1     Running   0          9m47s
    logtail-ds-zcpqs                          1/1     Running   0          9m33s
    logtail-ds-zx5hb                          1/1     Running   0          8m8s
  7. 修改logtail-ds资源限制及优先级
              resources:
                limits:
                  cpu: '2'
                  memory: 1Gi
                requests:
                  cpu: 40m
                  memory: 64Mi
    ...
    
          priorityClassName: base-resource
  8. 调整alibaba-log-controller节点亲和性
    # 资源限额
              resources:
                limits:
                  cpu: '1'
                  memory: 256Mi
                requests:
                  cpu: 10m
                  memory: 64Mi
    -------------------------------------------------
      # 节点亲和性
          affinity:
            nodeAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                nodeSelectorTerms:
                  - matchExpressions:
                      - key: kubernetes.io/resource
                        operator: In
                        values:
                          - base
    -------------------------------------------------------
    #污点配置
          tolerations:
            - key: resource
              value: base
              effect: NoExecute
    ----------------------------------------------------------
    #资源优先级
          priorityClassName: base-resource

     

标签:set,log,Kubernetes,--,alibaba,阿里,logtail,ds
来源: https://www.cnblogs.com/apink/p/15211690.html