-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add a shorter timeout instead of default 30 seconds for kindnetd listing nodes to speed up control-plane ready #2036
Comments
Hi, @BenTheElder, if this's ok to you, I would be happy to submit a pull request for this. |
@llhuii what do you mean exactly, that if the control-plane takes more than 30 seconds in start this will add an additional 30 seconds? |
Hi, @aojea, because the default i/o timeout is 30 seconds, here wants to make it shorter(e.g. 1 seconds), and ListOptions has a |
--update-- var DefaultTransport RoundTripper = &Transport{
Proxy: ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
} |
Another workaround I found is to add a cat > config.yaml <<EOF
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
# the default CNI will not be installed
#disableDefaultCNI: true
nodes:
- role: control-plane
# add a mount from /path/to/my/files on the host to /files on the node
extraMounts:
- hostPath: /tmp/default-cni.yaml
containerPath: /kind/manifests/default-cni.yaml
EOF
cat > /tmp/default-cni.yaml <EOF
# kindnetd networking manifest
# would you kindly template this file
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kindnet
rules:
- apiGroups:
- policy
resources:
- podsecuritypolicies
verbs:
- use
resourceNames:
- kindnet
- apiGroups:
- ""
resources:
- nodes
verbs:
- list
- watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kindnet
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kindnet
subjects:
- kind: ServiceAccount
name: kindnet
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kindnet
namespace: kube-system
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: kindnet
namespace: kube-system
labels:
tier: node
app: kindnet
k8s-app: kindnet
spec:
selector:
matchLabels:
app: kindnet
template:
metadata:
labels:
tier: node
app: kindnet
k8s-app: kindnet
spec:
hostNetwork: true
tolerations:
- operator: Exists
effect: NoSchedule
serviceAccountName: kindnet
initContainers:
- name: check-kube-proxy
image: busybox
command: ["sh"]
args:
- "-c"
- "echo before $(date); while ! timeout 1 nc -z $KUBERNETES_SERVICE_HOST $KUBERNETES_SERVICE_PORT_HTTPS; do date; done; echo done $(date)"
containers:
- name: kindnet-cni
image: kindest/kindnetd:v20210119-d5ef916d
env:
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_SUBNET
value: {{ .PodSubnet }}
volumeMounts:
- name: cni-cfg
mountPath: /etc/cni/net.d
- name: xtables-lock
mountPath: /run/xtables.lock
readOnly: false
- name: lib-modules
mountPath: /lib/modules
readOnly: true
resources:
requests:
cpu: "100m"
memory: "50Mi"
limits:
cpu: "100m"
memory: "50Mi"
securityContext:
privileged: false
capabilities:
add: ["NET_RAW", "NET_ADMIN"]
volumes:
- name: cni-cfg
hostPath:
path: /etc/cni/net.d
- name: xtables-lock
hostPath:
path: /run/xtables.lock
type: FileOrCreate
- name: lib-modules
hostPath:
path: /lib/modules
---
EOF
kind create cluster --config=config.yaml |
Also another way to cheat to speed up node ready: kind create cluster --name test
echo '
{
"cniVersion": "0.3.1",
"name": "kindnet",
"plugins": [
{ "type": "portmap" }
]
}
' | docker exec -i test-control-plane tee /etc/cni/net.d/10-kindnet.conflist
|
I see, thanks, so there are 3 points of improvement:
// createClients creates a kube client and an event client from the given config and masterOverride.
// TODO remove masterOverride when CLI flags are removed.
func createClients(config componentbaseconfig.ClientConnectionConfiguration, masterOverride string) (clientset.Interface, v1core.EventsGetter, error) {
var kubeConfig *rest.Config
var err error
if len(config.Kubeconfig) == 0 && len(masterOverride) == 0 {
klog.Info("Neither kubeconfig file nor master URL was specified. Falling back to in-cluster config.")
kubeConfig, err = rest.InClusterConfig()
} else {
// This creates a client, first loading any specified kubeconfig
// file, and then overriding the Master flag, if non-empty.
kubeConfig, err = clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: config.Kubeconfig},
&clientcmd.ConfigOverrides{ClusterInfo: clientcmdapi.Cluster{Server: masterOverride}}).ClientConfig()
}
I have started with 3 and I have to do some changes in kindnet for dual stack , so I will take 1 and 3 If you want, you can take 2. and drop an empty cniconfig if kind is going to use kindnetd |
Ok, I am glad to take 2. |
I found two ways to implement the 2nd improvement:
I prefer way 1 because only kindnet knows what's filename and content the cni plugin would be, Which one do you prefer? Or any other better ways? |
If we wait for kindnet we still have to wait for kubelet to create the kindnet pod. |
#2048 for this |
CNI placeholder does not seem to perform well, however bypassing the kube-apiserver VIP for the real endpoint is in #2043, note that it is not in a shipping node image yet, only when building a new node image will this be present. |
should we close this @BenTheElder with #2043 |
#2119 is what I was looking for to close this. |
Thank you, I will try it when free. |
Tested for the version
and the version
So shortened 24 seconds 🎉 |
What would you like to be added:
Add a timeout for
kind/images/kindnetd/cmd/kindnetd/main.go
Line 107 in 21c1d2e
Else kindnet would be timed out for 30 seconds in first time leading 30-seconds slower for control-plane node to be ready
Why is this needed:
I have a ci using kind to deploy k8s environment, I want to make control-plane node to be ready quickly.
Environment:
kind version
): kind v0.10.0-alpha go1.15.6 linux/amd64The text was updated successfully, but these errors were encountered: