refactor: wait-shutdown preStop hook is not necessary
/wait-shutdown preStop script's only job is to send SIGTERM to nginx-ingress-controller, which is PID 1, so it's the same with or without in Kubernetes environments. See https://github.com/kubernetes/ingress-nginx/issues/6287 for discussion.
This commit is contained in:
parent
3fe18f1870
commit
ff45a2a6af
7 changed files with 4 additions and 72 deletions
|
@ -57,13 +57,3 @@ ${GO_BUILD_CMD} \
|
|||
-X ${PKG}/version.REPO=${REPO_INFO}" \
|
||||
-buildvcs=false \
|
||||
-o "${TARGETS_DIR}/dbg" "${PKG}/cmd/dbg"
|
||||
|
||||
echo "Building ${PKG}/cmd/waitshutdown"
|
||||
|
||||
${GO_BUILD_CMD} \
|
||||
-trimpath -ldflags="-buildid= -w -s \
|
||||
-X ${PKG}/version.RELEASE=${TAG} \
|
||||
-X ${PKG}/version.COMMIT=${COMMIT_SHA} \
|
||||
-X ${PKG}/version.REPO=${REPO_INFO}" \
|
||||
-buildvcs=false \
|
||||
-o "${TARGETS_DIR}/wait-shutdown" "${PKG}/cmd/waitshutdown"
|
|
@ -372,7 +372,7 @@ metadata:
|
|||
| controller.keda.triggers | list | `[]` | |
|
||||
| controller.kind | string | `"Deployment"` | Use a `DaemonSet` or `Deployment` |
|
||||
| controller.labels | object | `{}` | Labels to be added to the controller Deployment or DaemonSet and other resources that do not have option to specify labels # |
|
||||
| controller.lifecycle | object | `{"preStop":{"exec":{"command":["/wait-shutdown"]}}}` | Improve connection draining when ingress controller pod is deleted using a lifecycle hook: With this new hook, we increased the default terminationGracePeriodSeconds from 30 seconds to 300, allowing the draining of connections up to five minutes. If the active connections end before that, the pod will terminate gracefully at that time. To effectively take advantage of this feature, the Configmap feature worker-shutdown-timeout new value is 240s instead of 10s. # |
|
||||
| controller.lifecycle | object | `{}` | |
|
||||
| controller.livenessProbe.failureThreshold | int | `5` | |
|
||||
| controller.livenessProbe.httpGet.path | string | `"/healthz"` | |
|
||||
| controller.livenessProbe.httpGet.port | int | `10254` | |
|
||||
|
|
|
@ -945,18 +945,7 @@ controller:
|
|||
# annotations:
|
||||
# description: Too many 4XXs
|
||||
# summary: More than 5% of all requests returned 4XX, this requires your attention
|
||||
# -- Improve connection draining when ingress controller pod is deleted using a lifecycle hook:
|
||||
# With this new hook, we increased the default terminationGracePeriodSeconds from 30 seconds
|
||||
# to 300, allowing the draining of connections up to five minutes.
|
||||
# If the active connections end before that, the pod will terminate gracefully at that time.
|
||||
# To effectively take advantage of this feature, the Configmap feature
|
||||
# worker-shutdown-timeout new value is 240s instead of 10s.
|
||||
##
|
||||
lifecycle:
|
||||
preStop:
|
||||
exec:
|
||||
command:
|
||||
- /wait-shutdown
|
||||
lifecycle: {}
|
||||
priorityClassName: ""
|
||||
# -- Rollback limit
|
||||
##
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
Copyright 2019 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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"k8s.io/ingress-nginx/internal/nginx"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := exec.Command("bash", "-c", "pkill -SIGTERM -f nginx-ingress-controller").Run()
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "terminating ingress controller")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// wait for the NGINX process to terminate
|
||||
timer := time.NewTicker(time.Second * 1)
|
||||
for range timer.C {
|
||||
if !nginx.IsRunning() {
|
||||
timer.Stop()
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,7 +43,6 @@ COPY --chown=www-data:www-data etc /etc
|
|||
|
||||
COPY --chown=www-data:www-data bin/${TARGETARCH}/dbg /
|
||||
COPY --chown=www-data:www-data bin/${TARGETARCH}/nginx-ingress-controller /
|
||||
COPY --chown=www-data:www-data bin/${TARGETARCH}/wait-shutdown /
|
||||
|
||||
# Fix permission during the build to avoid issues at runtime
|
||||
# with volumes (custom templates)
|
||||
|
|
|
@ -65,7 +65,6 @@ COPY --chown=www-data:www-data etc /chroot/etc
|
|||
|
||||
COPY --chown=www-data:www-data bin/${TARGETARCH}/dbg /
|
||||
COPY --chown=www-data:www-data bin/${TARGETARCH}/nginx-ingress-controller /
|
||||
COPY --chown=www-data:www-data bin/${TARGETARCH}/wait-shutdown /
|
||||
COPY --chown=www-data:www-data nginx-chroot-wrapper.sh /usr/bin/nginx
|
||||
|
||||
WORKDIR /chroot/etc/nginx
|
||||
|
|
|
@ -41,16 +41,14 @@ var _ = framework.IngressNginxDescribe("[Shutdown] Grace period shutdown", func(
|
|||
if strings.Contains(v, "--shutdown-grace-period") {
|
||||
continue
|
||||
}
|
||||
|
||||
args = append(args, v)
|
||||
}
|
||||
|
||||
args = append(args, "--shutdown-grace-period=90")
|
||||
deployment.Spec.Template.Spec.Containers[0].Args = args
|
||||
cmds := []string{"/wait-shutdown"}
|
||||
deployment.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command = cmds
|
||||
|
||||
grace := int64(3600)
|
||||
deployment.Spec.Template.Spec.TerminationGracePeriodSeconds = &grace
|
||||
|
||||
_, err := f.KubeClientSet.AppsV1().Deployments(f.Namespace).Update(context.TODO(), deployment, metav1.UpdateOptions{})
|
||||
return err
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue