Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set net.ipv4.tcp_keepalive_time and net.core.somaxconn for tidb and tikv in init container #1107

Merged
merged 4 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions charts/tidb-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ pd:
# # when the kubelet is configured to allow unsafe sysctls
# - name: net.core.somaxconn
# value: "32768"
# - name: net.ipv4.tcp_syncookies
# value: "0"
DanielZhangQD marked this conversation as resolved.
Show resolved Hide resolved
# - name: net.ipv4.tcp_tw_recycle
# value: "0"

# Specify the priorityClassName for PD Pod.
# refer to https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#how-to-use-priority-and-preemption
Expand Down Expand Up @@ -275,10 +271,6 @@ tikv:
# # when the kubelet is configured to allow unsafe sysctls
# - name: net.core.somaxconn
# value: "32768"
# - name: net.ipv4.tcp_syncookies
# value: "0"
# - name: net.ipv4.tcp_tw_recycle
# value: "0"

# Specify the priorityClassName for TiKV Pod.
# refer to https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#how-to-use-priority-and-preemption
Expand Down Expand Up @@ -362,10 +354,6 @@ tidb:
# # when the kubelet is configured to allow unsafe sysctls
# - name: net.core.somaxconn
# value: "32768"
# - name: net.ipv4.tcp_syncookies
# value: "0"
# - name: net.ipv4.tcp_tw_recycle
# value: "0"

# # Load balancers usually have an idle timeout (eg. AWS NLB idle timeout is 350),
# # the tcp_keepalive_time must be set to lower than LB idle timeout.
Expand Down
16 changes: 16 additions & 0 deletions deploy/modules/aliyun/tidb-cluster/values/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@ pd:
storage: 20Gi
storageClassName: alicloud-disk
tikv:
annotations:
tidb.pingcap.com/sysctl-init: "true"
podSecurityContext:
sysctls:
- name: net.core.somaxconn
value: "32768"
logLevel: info
storageClassName: local-volume
syncLog: true
tidb:
annotations:
tidb.pingcap.com/sysctl-init: "true"
podSecurityContext:
sysctls:
- name: net.core.somaxconn
value: "32768"
- name: net.ipv4.tcp_keepalive_intvl
value: "75"
- name: net.ipv4.tcp_keepalive_time
value: "300"
logLevel: info
service:
type: LoadBalancer
Expand Down
16 changes: 16 additions & 0 deletions deploy/modules/gcp/tidb-cluster/values/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@ timezone: UTC
pd:
storageClassName: pd-ssd
tikv:
annotations:
tidb.pingcap.com/sysctl-init: "true"
podSecurityContext:
sysctls:
- name: net.core.somaxconn
value: "32768"
storageClassName: local-storage
tidb:
annotations:
tidb.pingcap.com/sysctl-init: "true"
podSecurityContext:
sysctls:
- name: net.core.somaxconn
value: "32768"
- name: net.ipv4.tcp_keepalive_intvl
value: "75"
- name: net.ipv4.tcp_keepalive_time
value: "300"
service:
type: LoadBalancer
externalTrafficPolicy: Local
Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/controller_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ func TiKVCapacity(limits *v1alpha1.ResourceRequirement) string {
return fmt.Sprintf("%dMB", i/humanize.MiByte)
}

// Reuse the SlowLogTailer image for TiDB
func GetUtilImage(cluster *v1alpha1.TidbCluster) string {
if img := cluster.Spec.TiDB.SlowLogTailer.Image; img != "" {
return img
}
return defaultTiDBLogTailerImage
}

func GetSlowLogTailerImage(cluster *v1alpha1.TidbCluster) string {
if img := cluster.Spec.TiDB.SlowLogTailer.Image; img != "" {
return img
Expand Down
4 changes: 4 additions & 0 deletions pkg/label/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ const (
AnnForceUpgradeKey = "tidb.pingcap.com/force-upgrade"
// AnnPDDeferDeleting is pd pod annotation key in pod for defer for deleting pod
AnnPDDeferDeleting = "tidb.pingcap.com/pd-defer-deleting"
// AnnSysctlInit is pod annotation key to indicate whether configuring sysctls with init container
AnnSysctlInit = "tidb.pingcap.com/sysctl-init"

// AnnForceUpgradeVal is tc annotation value to indicate whether force upgrade should be done
AnnForceUpgradeVal = "true"
// AnnSysctlInitVal is pod annotation value to indicate whether configuring sysctls with init container
AnnSysctlInitVal = "true"

// PDLabelVal is PD label value
PDLabelVal string = "pd"
Expand Down
36 changes: 35 additions & 1 deletion pkg/manager/member/tidb_member_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,39 @@ func getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbCluster) *apps.StatefulSet {
})
}

sysctls := "sysctl -w"
var initContainers []corev1.Container
if tc.Spec.TiDB.Annotations != nil {
init, ok := tc.Spec.TiDB.Annotations[label.AnnSysctlInit]
if ok && (init == label.AnnSysctlInitVal) {
if tc.Spec.TiDB.PodSecurityContext != nil && len(tc.Spec.TiDB.PodSecurityContext.Sysctls) > 0 {
for _, sysctl := range tc.Spec.TiDB.PodSecurityContext.Sysctls {
sysctls = sysctls + fmt.Sprintf(" %s=%s", sysctl.Name, sysctl.Value)
}
privileged := true
initContainers = append(initContainers, corev1.Container{
Name: "init",
Image: controller.GetUtilImage(tc),
Command: []string{
"sh",
"-c",
sysctls,
},
SecurityContext: &corev1.SecurityContext{
Privileged: &privileged,
},
})
}
}
}
// Init container is only used for the case where allowed-unsafe-sysctls
// cannot be enabled for kubelet, so clean the sysctl in statefulset
// SecurityContext if init container is enabled
podSecurityContext := tc.Spec.TiDB.PodSecurityContext.DeepCopy()
if len(initContainers) > 0 {
podSecurityContext.Sysctls = []corev1.Sysctl{}
}

var containers []corev1.Container
if tc.Spec.TiDB.SeparateSlowLog {
// mount a shared volume and tail the slow log to STDOUT using a sidecar.
Expand Down Expand Up @@ -383,8 +416,9 @@ func getNewTiDBSetForTidbCluster(tc *v1alpha1.TidbCluster) *apps.StatefulSet {
RestartPolicy: corev1.RestartPolicyAlways,
Tolerations: tc.Spec.TiDB.Tolerations,
Volumes: vols,
SecurityContext: tc.Spec.TiDB.PodSecurityContext,
SecurityContext: podSecurityContext,
PriorityClassName: tc.Spec.TiDB.PriorityClassName,
InitContainers: initContainers,
},
},
ServiceName: controller.TiDBPeerMemberName(tcName),
Expand Down
Loading