Skip to content

Commit aeca6a2

Browse files
authored
add liveness probe and adjust cpu/mem limit (#1530)
1 parent f16e9e6 commit aeca6a2

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

config/controller/controller.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ spec:
2929
- --ingress-class=alb
3030
resources:
3131
limits:
32-
cpu: 100m
33-
memory: 2000Mi
32+
cpu: 200m
33+
memory: 500Mi
3434
requests:
3535
cpu: 100m
3636
memory: 200Mi
37+
livenessProbe:
38+
failureThreshold: 2
39+
httpGet:
40+
path: /healthz
41+
port: 61779
42+
scheme: HTTP
43+
initialDelaySeconds: 30
44+
timeoutSeconds: 10
3745
terminationGracePeriodSeconds: 10
3846
serviceAccountName: controller

main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ import (
3939
"sigs.k8s.io/aws-load-balancer-controller/pkg/runtime"
4040
"sigs.k8s.io/aws-load-balancer-controller/pkg/targetgroupbinding"
4141
"sigs.k8s.io/aws-load-balancer-controller/pkg/version"
42-
ctrl "sigs.k8s.io/controller-runtime"
4342
corewebhook "sigs.k8s.io/aws-load-balancer-controller/webhooks/core"
4443
elbv2webhook "sigs.k8s.io/aws-load-balancer-controller/webhooks/elbv2"
44+
ctrl "sigs.k8s.io/controller-runtime"
45+
"sigs.k8s.io/controller-runtime/pkg/healthz"
4546
"sigs.k8s.io/controller-runtime/pkg/log/zap"
4647
"sigs.k8s.io/controller-runtime/pkg/metrics"
4748
// +kubebuilder:scaffold:imports
@@ -126,6 +127,14 @@ func main() {
126127
os.Exit(1)
127128
}
128129

130+
// Add liveness probe
131+
err = mgr.AddHealthzCheck("health-ping", healthz.Ping)
132+
setupLog.Info("adding health check for controller")
133+
if err != nil {
134+
setupLog.Error(err, "unable add a health check")
135+
os.Exit(1)
136+
}
137+
129138
podReadinessGateInjector := inject.NewPodReadinessGate(controllerCFG.PodWebhookConfig,
130139
mgr.GetClient(), ctrl.Log.WithName("pod-readiness-gate-injector"))
131140
corewebhook.NewPodMutator(podReadinessGateInjector).SetupWithManager(mgr)

pkg/config/runtime_config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
const (
1414
flagMetricsBindAddr = "metrics-bind-addr"
15+
flagHealthProbeBindAddr = "health-probe-bind-addr"
1516
flagWebhookBindPort = "webhook-bind-port"
1617
flagEnableLeaderElection = "enable-leader-election"
1718
flagLeaderElectionID = "leader-election-id"
@@ -25,6 +26,7 @@ const (
2526
defaultLeaderElectionNamespace = ""
2627
defaultWatchNamespace = corev1.NamespaceAll
2728
defaultMetricsAddr = ":8080"
29+
defaultHealthProbeBindAddress = ":61779"
2830
defaultSyncPeriod = 60 * time.Minute
2931
defaultWebhookBindPort = 9443
3032
// High enough QPS to fit all expected use cases. QPS=0 is not set here, because
@@ -41,6 +43,7 @@ type RuntimeConfig struct {
4143
KubeConfig string
4244
WebhookBindPort int
4345
MetricsBindAddress string
46+
HealthProbeBindAddress string
4447
EnableLeaderElection bool
4548
LeaderElectionID string
4649
LeaderElectionNamespace string
@@ -54,6 +57,8 @@ func (c *RuntimeConfig) BindFlags(fs *pflag.FlagSet) {
5457
"Path to the kubeconfig file containing authorization and API server information.")
5558
fs.StringVar(&c.MetricsBindAddress, flagMetricsBindAddr, defaultMetricsAddr,
5659
"The address the metric endpoint binds to.")
60+
fs.StringVar(&c.HealthProbeBindAddress, flagHealthProbeBindAddr, defaultHealthProbeBindAddress,
61+
"The address the health probes binds to.")
5762
fs.IntVar(&c.WebhookBindPort, flagWebhookBindPort, defaultWebhookBindPort,
5863
"The TCP port the Webhook server binds to.")
5964
fs.BoolVar(&c.EnableLeaderElection, flagEnableLeaderElection, true,
@@ -94,6 +99,7 @@ func BuildRuntimeOptions(rtCfg RuntimeConfig, scheme *runtime.Scheme) ctrl.Optio
9499
Scheme: scheme,
95100
Port: rtCfg.WebhookBindPort,
96101
MetricsBindAddress: rtCfg.MetricsBindAddress,
102+
HealthProbeBindAddress: rtCfg.HealthProbeBindAddress,
97103
LeaderElection: rtCfg.EnableLeaderElection,
98104
LeaderElectionID: rtCfg.LeaderElectionID,
99105
LeaderElectionNamespace: rtCfg.LeaderElectionNamespace,

0 commit comments

Comments
 (0)