通过 terraform 在 AKS 节点池上运行 shell 脚本或自定义数据

发布于 2025-01-12 10:59:38 字数 202 浏览 0 评论 0原文

我想通过 terraform 脚本在 AKS 节点池上运行 shell 脚本或自定义数据。我通过 terraform 通过 VMSS(虚拟机规模集)上的自定义数据运行 shell 脚本。同样,我想通过 AKS 节点池运行相同的 shell 脚本。我搜索了很多链接和方法,但找不到任何解决方案。有什么办法或者推荐吗?感谢您的帮助。一个月以来我一直在尝试这个解决方案,但无法得到正确的解决方案。

I would like to run shell script or custom data on AKS node pool via terraform script. I ran shell script via custom data on VMSS (Virtual machine scale set) through terraform.Similarly I would like to run the same shell script via AKS node pool. I searched many link and ways but couldn't get any solution for this. Is there any way or recommended this? Appreciate your help.I have been trying for this solution since a month but couldn't get proper solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

血之狂魔 2025-01-19 10:59:38

我通过 deamonset 和 configmap 与 nodeinstaller 获得了解决方案。
下面的链接确实对我有帮助,但不是通过 terraform,因为 AKS 不支持通过 terraform 实现自动化的自定义脚本。(您好,我可以在 AKS 节点组中执行自定义脚本吗?

参考链接:https://medium.com/@patnaikshekhar/initialize-your- aks-nodes-with-daemonsets-679fa81fd20e

https://github.com/patnaikshekhar/AKSNodeInstaller

daemonset.yml

apiVersion: v1
kind: Namespace
metadata:
  name: node-installer
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: installer
  namespace: node-installer
spec:
  selector:
    matchLabels:
      job: installer
  template:
    metadata:
      labels:
        job: installer
    spec:
      hostPID: true
      restartPolicy: Always
      containers:
      - image: patnaikshekhar/node-installer:1.3
        name: installer
        securityContext:
          privileged: true
        volumeMounts:
        - name: install-script
          mountPath: /tmp
        - name: host-mount
          mountPath: /host
      volumes:
      - name: install-script
        configMap:
          name: sample-installer-config
      - name: host-mount
        hostPath:
          path: /tmp/install

示例configmap.yml

apiVersion: v1
kind: ConfigMap
metadata:
  name: sample-installer-config
  namespace: node-installer
data:
  install.sh: |
    #!/bin/bash

    # install newrelic-infra
    echo "license_key: #{NEW_RELIC_LICENSE_KEY}#" | sudo tee -a /etc/newrelic-infra.yml
    echo "enabled: #{NEW_RELIC_INFRA_AGENT_ENABLED}#" | sudo tee -a /etc/newrelic-infra.yml

    curl -s https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg | sudo apt-key add -
    printf "deb https://download.newrelic.com/infrastructure_agent/linux/apt bionic main" | sudo tee -a /etc/apt/sources.list.d/newrelic-infra.list
    sudo apt-get update -y
    sudo apt-get install newrelic-infra -y
    sudo systemctl status newrelic-infra
    echo "Newrelic infra agent installation is done"

    # enable log forwarding
    echo "logs:" | sudo tee -a /etc/newrelic-infra/logging.d/logs.yml
    echo "  - name: log-files-in-folder" | sudo tee -a /etc/newrelic-infra/logging.d/logs.yml
    echo "    file: /var/log/onefc/*/*.newrelic.log" | sudo tee -a /etc/newrelic-infra/logging.d/logs.yml
    echo "    max_line_kb: 256" | sudo tee -a /etc/newrelic-infra/logging.d/logs.yml

    # trigger log forwarding
    sudo newrelic-infra-ctl

I have got my solution via deamonset and configmap with nodeinstaller.
Below links really helped me but not through terraform as AKS won't support custom script to automate via terraform.(Hi can I have a custom script to be executed in AKS node group?)

Reference links: https://medium.com/@patnaikshekhar/initialize-your-aks-nodes-with-daemonsets-679fa81fd20e

https://github.com/patnaikshekhar/AKSNodeInstaller

daemonset.yml

apiVersion: v1
kind: Namespace
metadata:
  name: node-installer
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: installer
  namespace: node-installer
spec:
  selector:
    matchLabels:
      job: installer
  template:
    metadata:
      labels:
        job: installer
    spec:
      hostPID: true
      restartPolicy: Always
      containers:
      - image: patnaikshekhar/node-installer:1.3
        name: installer
        securityContext:
          privileged: true
        volumeMounts:
        - name: install-script
          mountPath: /tmp
        - name: host-mount
          mountPath: /host
      volumes:
      - name: install-script
        configMap:
          name: sample-installer-config
      - name: host-mount
        hostPath:
          path: /tmp/install

sampleconfigmap.yml

apiVersion: v1
kind: ConfigMap
metadata:
  name: sample-installer-config
  namespace: node-installer
data:
  install.sh: |
    #!/bin/bash

    # install newrelic-infra
    echo "license_key: #{NEW_RELIC_LICENSE_KEY}#" | sudo tee -a /etc/newrelic-infra.yml
    echo "enabled: #{NEW_RELIC_INFRA_AGENT_ENABLED}#" | sudo tee -a /etc/newrelic-infra.yml

    curl -s https://download.newrelic.com/infrastructure_agent/gpg/newrelic-infra.gpg | sudo apt-key add -
    printf "deb https://download.newrelic.com/infrastructure_agent/linux/apt bionic main" | sudo tee -a /etc/apt/sources.list.d/newrelic-infra.list
    sudo apt-get update -y
    sudo apt-get install newrelic-infra -y
    sudo systemctl status newrelic-infra
    echo "Newrelic infra agent installation is done"

    # enable log forwarding
    echo "logs:" | sudo tee -a /etc/newrelic-infra/logging.d/logs.yml
    echo "  - name: log-files-in-folder" | sudo tee -a /etc/newrelic-infra/logging.d/logs.yml
    echo "    file: /var/log/onefc/*/*.newrelic.log" | sudo tee -a /etc/newrelic-infra/logging.d/logs.yml
    echo "    max_line_kb: 256" | sudo tee -a /etc/newrelic-infra/logging.d/logs.yml

    # trigger log forwarding
    sudo newrelic-infra-ctl
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文