From 1aba1bc9fed7063265bc3b726628ad1bd0badc83 Mon Sep 17 00:00:00 2001 From: Jitendra Bhurat Date: Fri, 4 Nov 2016 13:44:21 -0400 Subject: [PATCH 1/3] Powershell script to start kubelet and kube-proxy --- cluster/windows/kube-startup.ps1 | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 cluster/windows/kube-startup.ps1 diff --git a/cluster/windows/kube-startup.ps1 b/cluster/windows/kube-startup.ps1 new file mode 100644 index 00000000000..dbd47f85fa6 --- /dev/null +++ b/cluster/windows/kube-startup.ps1 @@ -0,0 +1,46 @@ +#!/bin/bash + +# Copyright 2016 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# kube-startup.ps1 is used to run kubelet and kubeproxy as a process. The processes can be viewed using TaskManager(Taskmgr.exe). +# Please note that this startup script does not start the API server. Kubernetes control plane currently runs on Linux +# and only Kubelet and Kube-Proxy can be run on Windows + +param ( + [Parameter(Mandatory=$true)][string]$ContainerNetwork, + [string]$InterfaceForServiceIP = "vEthernet (HNS Internal NIC)", + [string]$LogDirectory = "C:\temp", + [Parameter(Mandatory=$true)][string]$Hostname, + [Parameter(Mandatory=$true)][string]$APIServer, + [string]$InfraContainerImage = "apprenda/pause", + [string]$ClusterDNS = "10.0.0.10", + [string]$KubeletExePath = ".\kubelet.exe", + [string]$KubeProxyExePath = ".\kube-proxy.exe" +) + +# CONTAINER_NETWORK environment variable is used by kubelet and is used to determine the Docker network to be used by PODs +$env:CONTAINER_NETWORK = $ContainerNetwork + +# INTERFACE_TO_ADD_SERVICE_IP environment variable to which Services IPs will be added. By Default "vEthernet (HNS Internal NIC)" which is created by +# when Docker is installed is used as it is private to the Host +$env:INTERFACE_TO_ADD_SERVICE_IP = $InterfaceForServiceIP + +# Runs the kubelet with the user provided or default options +Start-Process -FilePath "$KubeletExePath" -ArgumentList --hostname-override=$Hostname, --pod-infra-container-image=$InfraContainerImage, ` +--resolv-conf=, --api-servers=$APIServer, --cluster-dns=$ClusterDNS -RedirectStandardError "$LogDirectory\kubelet.log" -NoNewWindow + +# Runs the kube-proxy with the user provided or default options +Start-Process -FilePath "$KubeProxyExePath" -ArgumentList --proxy-mode=userspace, --hostname-override=$Hostname, --master=$APIServer, ` +--bind-address=$Hostname -RedirectStandardError "$LogDirectory\kube-proxy.log" -NoNewWindow \ No newline at end of file From 3a8ba99d300fbd28b30d0ef7fa59ac517943f827 Mon Sep 17 00:00:00 2001 From: Jitendra Bhurat Date: Fri, 2 Dec 2016 14:04:43 -0500 Subject: [PATCH 2/3] Updated the script to use nssm service manager Updated the script to use nssm service manager instead of Start-Process as it supports log rotation and auto restart of Services on host reboot --- cluster/windows/kube-startup.ps1 | 73 ++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/cluster/windows/kube-startup.ps1 b/cluster/windows/kube-startup.ps1 index dbd47f85fa6..98e73be2115 100644 --- a/cluster/windows/kube-startup.ps1 +++ b/cluster/windows/kube-startup.ps1 @@ -1,5 +1,3 @@ -#!/bin/bash - # Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# kube-startup.ps1 is used to run kubelet and kubeproxy as a process. The processes can be viewed using TaskManager(Taskmgr.exe). +# kube-startup.ps1 is used to run kubelet and kubeproxy as a process. It uses nssm (https://nssm.cc/) process manager to register kubelet and kube-proxy process, +# The processes can be viewed using TaskManager(Taskmgr.exe). # Please note that this startup script does not start the API server. Kubernetes control plane currently runs on Linux # and only Kubelet and Kube-Proxy can be run on Windows @@ -30,17 +29,63 @@ param ( [string]$KubeProxyExePath = ".\kube-proxy.exe" ) -# CONTAINER_NETWORK environment variable is used by kubelet and is used to determine the Docker network to be used by PODs -$env:CONTAINER_NETWORK = $ContainerNetwork +$kubeletDirectory = (Get-Item $KubeletExePath).Directory.FullName +$kubeproxyDirectory = (Get-Item $KubeProxyExePath).Directory.FullName -# INTERFACE_TO_ADD_SERVICE_IP environment variable to which Services IPs will be added. By Default "vEthernet (HNS Internal NIC)" which is created by -# when Docker is installed is used as it is private to the Host -$env:INTERFACE_TO_ADD_SERVICE_IP = $InterfaceForServiceIP +# Assemble the Kubelet executable arguments +$kubeletArgs = @("--hostname-override=$Hostname","--pod-infra-container-image=$InfraContainerImage","--resolv-conf=""""","--api-servers=$APIServer","--cluster-dns=$ClusterDNS") +# Assemble the kube-proxy executable arguments +$kubeproxyArgs = @("--hostname-override=$Hostname","--proxy-mode=userspace","--bind-address=$Hostname","--master=$APIServer") -# Runs the kubelet with the user provided or default options -Start-Process -FilePath "$KubeletExePath" -ArgumentList --hostname-override=$Hostname, --pod-infra-container-image=$InfraContainerImage, ` ---resolv-conf=, --api-servers=$APIServer, --cluster-dns=$ClusterDNS -RedirectStandardError "$LogDirectory\kubelet.log" -NoNewWindow +# Setup kubelet service +nssm install kubelet "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" +nssm set kubelet Application "$KubeletExePath" +nssm set kubelet AppDirectory "$kubeletDirectory" +nssm set kubelet AppParameters $kubeletArgs +nssm set kubelet DisplayName kubelet +nssm set kubelet Description kubelet +nssm set kubelet Start SERVICE_AUTO_START +nssm set kubelet ObjectName LocalSystem +nssm set kubelet Type SERVICE_WIN32_OWN_PROCESS +# Delay restart if application runs for less than 1500 ms +nssm set kubelet AppThrottle 1500 +nssm set kubelet AppStdout "$LogDirectory\kubelet.log" +nssm set kubelet AppStderr "$LogDirectory\kubelet.err.log" +nssm set kubelet AppStdoutCreationDisposition 4 +nssm set kubelet AppStderrCreationDisposition 4 +nssm set kubelet AppRotateFiles 1 +nssm set kubelet AppRotateOnline 1 +# Rotate Logs Every 24 hours or 1 gb +nssm set kubelet AppRotateSeconds 86400 +nssm set kubelet AppRotateBytes 1048576 +nssm set kubelet AppEnvironmentExtra CONTAINER_NETWORK=$ContainerNetwork -# Runs the kube-proxy with the user provided or default options -Start-Process -FilePath "$KubeProxyExePath" -ArgumentList --proxy-mode=userspace, --hostname-override=$Hostname, --master=$APIServer, ` ---bind-address=$Hostname -RedirectStandardError "$LogDirectory\kube-proxy.log" -NoNewWindow \ No newline at end of file + +# Setup kube-proxy service +nssm install kube-proxy "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" +nssm set kube-proxy Application "$KubeProxyExePath" +nssm set kube-proxy AppDirectory "$kubeproxyDirectory" +nssm set kube-proxy AppParameters $kubeproxyArgs +nssm set kube-proxy DisplayName kube-proxy +nssm set kube-proxy Description kube-proxy +nssm set kube-proxy Start SERVICE_AUTO_START +nssm set kube-proxy ObjectName LocalSystem +nssm set kube-proxy Type SERVICE_WIN32_OWN_PROCESS +# Delay restart if application runs for less than 1500 ms +nssm set kube-proxy AppThrottle 1500 +nssm set kube-proxy AppStdout "$LogDirectory\kube-proxy.log" +nssm set kube-proxy AppStderr "$LogDirectory\kube-proxy.err.log" +nssm set kube-proxy AppStdoutCreationDisposition 4 +nssm set kube-proxy AppStderrCreationDisposition 4 +nssm set kube-proxy AppRotateFiles 1 +nssm set kube-proxy AppRotateOnline 1 +# Rotate Logs Every 24 hours or 1 gb +nssm set kube-proxy AppRotateSeconds 86400 +nssm set kube-proxy AppRotateBytes 1048576 +nssm set kube-proxy AppEnvironmentExtra INTERFACE_TO_ADD_SERVICE_IP=$InterfaceForServiceIP + +# Start kubelet and kube-proxy Services +echo "Starting kubelet" +Start-Service kubelet +echo "Starting kube-proxy" +Start-Service kube-proxy From a6f50e067862b0a98be57a3519ac6b6cc09a265c Mon Sep 17 00:00:00 2001 From: Jitendra Bhurat Date: Mon, 12 Dec 2016 11:08:41 -0500 Subject: [PATCH 3/3] Fixed the issue with log rotation Fixed the issue where log files where being rotated every 1mb instead of 1gb --- cluster/windows/kube-startup.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cluster/windows/kube-startup.ps1 b/cluster/windows/kube-startup.ps1 index 98e73be2115..4f531407bb9 100644 --- a/cluster/windows/kube-startup.ps1 +++ b/cluster/windows/kube-startup.ps1 @@ -57,7 +57,7 @@ nssm set kubelet AppRotateFiles 1 nssm set kubelet AppRotateOnline 1 # Rotate Logs Every 24 hours or 1 gb nssm set kubelet AppRotateSeconds 86400 -nssm set kubelet AppRotateBytes 1048576 +nssm set kubelet AppRotateBytes 1073741824 nssm set kubelet AppEnvironmentExtra CONTAINER_NETWORK=$ContainerNetwork @@ -81,7 +81,7 @@ nssm set kube-proxy AppRotateFiles 1 nssm set kube-proxy AppRotateOnline 1 # Rotate Logs Every 24 hours or 1 gb nssm set kube-proxy AppRotateSeconds 86400 -nssm set kube-proxy AppRotateBytes 1048576 +nssm set kube-proxy AppRotateBytes 1073741824 nssm set kube-proxy AppEnvironmentExtra INTERFACE_TO_ADD_SERVICE_IP=$InterfaceForServiceIP # Start kubelet and kube-proxy Services