diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..64307f1a2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +FROM mcr.microsoft.com/windows/servercore:ltsc2019 + +SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] + +RUN Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) +RUN choco install python git -y + +RUN python -m pip install --upgrade pip +RUN pip install --upgrade --no-cache-dir \ + orjson==3.6.8 \ + zstandard==0.17.0 \ + lz4==4.0.0 \ + requests==2.25.1 \ + docker==4.1.0 \ + psutil + +WORKDIR /Scalyr +ADD . /Scalyr +ADD ./docker/k8s-config/ /Scalyr/config + +RUN Get-Content /Scalyr/certs/*.pem | Set-Content /Scalyr/certs/ca_certs.crt +RUN "[Environment]::SetEnvironmentVariable('PYTHONUTF8', '1', 'Machine')" +ENV SCALYR_STDOUT_SEVERITY ERROR +ENV SCALYR_K8S_KUBELET_CA_CERT /var/run/secrets/kubernetes.io/serviceaccount/ca.crt +ENV SCALYR_K8S_SERVICE_ACCOUNT_CERT /var/run/secrets/kubernetes.io/serviceaccount/ca.crt +CMD ["python", "-X", "utf8", "/Scalyr/scalyr_agent/agent_main.py", "--no-fork", "--no-change-user", "--verbose", "start"] \ No newline at end of file diff --git a/k8s-windows/scalyr-windows-agent.yaml b/k8s-windows/scalyr-windows-agent.yaml new file mode 100644 index 000000000..e914c4fa8 --- /dev/null +++ b/k8s-windows/scalyr-windows-agent.yaml @@ -0,0 +1,107 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + labels: + app: windows-scalyr-agent + name: winscaler-config-agent-d + namespace: scalyr +data: + "kubernetes.json": | + { + "monitors":[ + { + "module": "scalyr_agent.builtin_monitors.kubernetes_events_monitor" + }, + { + "module": "scalyr_agent.builtin_monitors.kubernetes_monitor", + "report_container_metrics": true, + "report_k8s_metrics": true + } + ] + } +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + labels: + app: windows-scalyr-agent + name: windows-scalyr-agent + namespace: scalyr +spec: + selector: + matchLabels: + app: windows-scalyr-agent + template: + metadata: + labels: + app: windows-scalyr-agent + spec: + containers: + - name: winscaler + image: winscaler:latest + env: + - name: SCALYR_SERVER + value: agent.scalyr.com + - name: SCALYR_API_KEY + value: + - name: SCALYR_K8S_CLUSTER_NAME + value: winscaler-test + - name: SCALYR_K8S_VERIFY_KUBELET_QUERIES + value: "true" + - name: SCALYR_K8S_API_URL + value: https://kubernetes.default.svc.cluster.local + - name: "SCALYR_K8S_NODE_NAME" + valueFrom: + fieldRef: + fieldPath: "spec.nodeName" + apiVersion: "v1" + - name: "SCALYR_K8S_POD_NAME" + valueFrom: + fieldRef: + fieldPath: "metadata.name" + apiVersion: "v1" + - name: "SCALYR_K8S_POD_NAMESPACE" + valueFrom: + fieldRef: + fieldPath: "metadata.namespace" + apiVersion: "v1" + - name: "SCALYR_K8S_POD_UID" + valueFrom: + fieldRef: + fieldPath: "metadata.uid" + apiVersion: "v1" + - name: "SCALYR_K8S_KUBELET_HOST_IP" + valueFrom: + fieldRef: + fieldPath: "status.hostIP" + apiVersion: "v1" + volumeMounts: + - name: varlogpods + mountPath: "/var/log/pods" + readOnly: true + - name: varlogcontainers + mountPath: "/var/log/containers" + readOnly: true + - name: "scalyr-config-agent-d" + mountPath: "/etc/scalyr-agent-2/agent.d" + nodeSelector: + kubernetes.io/os: windows + tolerations: + - key: "kubernetes.azure.com/scalesetpriority" + operator: "Equal" + value: "spot" + effect: "NoSchedule" + volumes: + - name: "varlogpods" + hostPath: + path: "/var/log/pods" + - name: "varlogcontainers" + hostPath: + path: "/var/log/containers" + - name: "scalyr-config-agent-d" + configMap: + name: winscaler-config-agent-d + defaultMode: 0600 + dnsPolicy: "ClusterFirst" + automountServiceAccountToken: true + serviceAccountName: scalyr-scalyr-agent-sa # use service account from default scalyr helm installation \ No newline at end of file diff --git a/scalyr_agent/platform_windows.py b/scalyr_agent/platform_windows.py index c48a5a48d..5fd280cfd 100644 --- a/scalyr_agent/platform_windows.py +++ b/scalyr_agent/platform_windows.py @@ -567,7 +567,10 @@ def is_agent_running(self, fail_if_running=False, fail_if_not_running=False): win32service.SERVICE_RUNNING, win32service.SERVICE_START_PENDING, ) - + except: + # When running the script without a service on windows, this will fail + # If we return false here, we can use it without a service + return False finally: if hs is not None: win32service.CloseServiceHandle(hs)