|
| 1 | +--- |
| 2 | +title: 5.7 Enable Kubelet Proxy |
| 3 | +date: 2025-08-22T13:00:03+08:00 |
| 4 | +description: How to enable Koupleless Module Controller V2 Kubelet Proxy |
| 5 | +weight: 1100 |
| 6 | +--- |
| 7 | + |
| 8 | +## Kubelet Proxy |
| 9 | + |
| 10 | +Kubelet Proxy is an enhanced feature of Module Controller V2 on the K8s side. |
| 11 | +It allows users to interact directly with Module Controller V2 using the ``kubectl`` tool, |
| 12 | +providing an operational experience similar to the native K8s Kubelet. |
| 13 | + |
| 14 | +For design details, please refer to |
| 15 | +the [documentation](/docs/contribution-guidelines/module-controller-v2/virtual-kubelet-proxy). |
| 16 | + |
| 17 | +## Enable Kubelet Proxy |
| 18 | + |
| 19 | +0. Deploy cert-manager to manage certificate generation and rotation |
| 20 | + cert-manager is a Kubernetes plugin for automating the management and rotation of TLS certificates. It helps generate |
| 21 | + and manage TLS certificates used for the Kubelet Proxy. |
| 22 | + Please refer to the [cert-manager documentation](https://cert-manager.io/docs/installation/) for installation |
| 23 | + instructions. |
| 24 | + Here is a simple installation example (v1.18.2): |
| 25 | + |
| 26 | +```bash |
| 27 | +kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.18.2/cert-manager.yaml |
| 28 | +``` |
| 29 | + |
| 30 | +After successful deployment, deploy the corresponding Issuer and Certificate: |
| 31 | + |
| 32 | +- To create Issuer |
| 33 | + |
| 34 | +```yaml |
| 35 | +apiVersion: cert-manager.io/v1 |
| 36 | +kind: ClusterIssuer |
| 37 | +metadata: |
| 38 | + name: virtual-kubelet-issuer |
| 39 | +spec: |
| 40 | + selfSigned: {} |
| 41 | +``` |
| 42 | +
|
| 43 | +- To create Cert |
| 44 | +
|
| 45 | +```yaml |
| 46 | +apiVersion: cert-manager.io/v1 |
| 47 | +kind: Certificate |
| 48 | +metadata: |
| 49 | + name: virtual-kubelet-cert |
| 50 | +spec: |
| 51 | + secretName: virtual-kubelet-tls # secretName: virtual-kubelet-tls # The name of the Secret where the certificate is stored, which will be used later in the ModuleController |
| 52 | + duration: 2160h # 90 days |
| 53 | + renewBefore: 360h # renew 15 days before expiration |
| 54 | + issuerRef: |
| 55 | + name: virtual-kubelet-issuer # Reference to the above Issuer |
| 56 | + kind: ClusterIssuer |
| 57 | + commonName: koupleless-virtual-kubelet # Common Name |
| 58 | + usages: |
| 59 | + - server auth |
| 60 | + - digital signature |
| 61 | + - key encipherment |
| 62 | +``` |
| 63 | +
|
| 64 | +After creation, you can use the following command to check whether the certificate secret was generated successfully: |
| 65 | +
|
| 66 | +If the output is similar to the following, the certificate has been generated successfully: |
| 67 | +
|
| 68 | +```bash |
| 69 | +kubectl get secret virtual-kubelet-tls |
| 70 | +``` |
| 71 | + |
| 72 | +If the output is similar to the following, the certificate has been generated successfully: |
| 73 | + |
| 74 | +``` |
| 75 | +NAME TYPE DATA AGE |
| 76 | +virtual-kubelet-tls kubernetes.io/tls 3 1m |
| 77 | +``` |
| 78 | + |
| 79 | +1. Add `pods/log` permission to the Role |
| 80 | + |
| 81 | +```yaml |
| 82 | +kind: ClusterRole |
| 83 | +apiVersion: rbac.authorization.k8s.io/v1 |
| 84 | +metadata: |
| 85 | + name: virtual-kubelet-role |
| 86 | +rules: |
| 87 | + - apiGroups: [""] # "" indicates the core API group |
| 88 | + resources: ["pods" , "pods/status", "pods/spec","nodes", "nodes/status", "events", "pods/log"] |
| 89 | + verbs: ["get", "watch", "list", "update", "patch", "create", "delete"] |
| 90 | + - apiGroups: [ "apps" ] |
| 91 | + resources: [ "deployments", "deployments/status", "deployments/spec", "daemonSets", "daemonSets/status", "daemonSets/spec" ] |
| 92 | + verbs: [ "get", "watch", "list" ] |
| 93 | + - apiGroups: [""] # "" indicates the core API group |
| 94 | + resources: ["configmaps", "secrets", "services"] |
| 95 | + verbs: ["get", "watch", "list"] |
| 96 | + - apiGroups: ["coordination.k8s.io"] # "" indicates the core API group |
| 97 | + resources: ["leases"] |
| 98 | + verbs: ["get", "watch", "list", "update", "patch", "create", "delete"] |
| 99 | +``` |
| 100 | +
|
| 101 | +2. Create a Service for the ModuleController deployment |
| 102 | +
|
| 103 | +```yaml |
| 104 | +apiVersion: v1 |
| 105 | +kind: Service |
| 106 | +metadata: |
| 107 | + name: module-controller |
| 108 | + namespace: default |
| 109 | + labels: |
| 110 | + app: module-controller |
| 111 | + virtual-kubelet.koupleless.io/kubelet-proxy-service: "true" # Necessary, indicates that this Service is used for Kubelet Proxy |
| 112 | +spec: |
| 113 | + selector: |
| 114 | + app: module-controller |
| 115 | + ports: |
| 116 | + - name: httptunnel # If HTTP tunneling is not enabled, please remove this port |
| 117 | + port: 7777 |
| 118 | + targetPort: 7777 |
| 119 | + - name: kubelet-proxy # Kubelet Proxy port |
| 120 | + port: 10250 |
| 121 | + type: ClusterIP |
| 122 | +``` |
| 123 | +
|
| 124 | +3. Modify the ENV configuration of ModuleController |
| 125 | +
|
| 126 | +```yaml |
| 127 | +apiVersion: apps/v1 |
| 128 | +kind: Deployment |
| 129 | +metadata: |
| 130 | + name: module-controller |
| 131 | +spec: |
| 132 | + replicas: 1 |
| 133 | + selector: |
| 134 | + matchLabels: |
| 135 | + app: module-controller |
| 136 | + template: |
| 137 | + metadata: |
| 138 | + labels: |
| 139 | + app: module-controller |
| 140 | + spec: |
| 141 | + serviceAccountName: virtual-kubelet |
| 142 | + volumes: |
| 143 | + - name: tls-certs |
| 144 | + secret: |
| 145 | + secretName: virtual-kubelet-tls # Necessary, mount the TLS certificate generated by cert-manager |
| 146 | + containers: |
| 147 | + - name: module-controller |
| 148 | + image: serverless-registry.cn-shanghai.cr.aliyuncs.com/opensource/release/module-controller-v2:<VERSION> # Please replace <VERSION> with the actual version number, e.g., v2.1.4 |
| 149 | + imagePullPolicy: IfNotPresent |
| 150 | + resources: |
| 151 | + limits: |
| 152 | + cpu: "1000m" |
| 153 | + memory: "400Mi" |
| 154 | + ports: |
| 155 | + - name: httptunnel # If HTTP tunneling is not enabled, please remove this port |
| 156 | + containerPort: 7777 |
| 157 | + - name: kubelet-proxy # Kubelet Proxy port |
| 158 | + containerPort: 10250 |
| 159 | + env: |
| 160 | + - name: ENABLE_HTTP_TUNNEL |
| 161 | + value: "true" |
| 162 | + - name: NAMESPACE # Necessary, the namespace where ModuleController is deployed |
| 163 | + valueFrom: |
| 164 | + fieldRef: |
| 165 | + fieldPath: metadata.namespace |
| 166 | + - name: KUBELET_PROXY_ENABLED # Necessary, enable Kubelet Proxy |
| 167 | + value: "true" |
| 168 | + volumeMounts: # Necessary, mount the TLS certificate generated by cert-manager |
| 169 | + - name: tls-certs |
| 170 | + mountPath: /etc/virtual-kubelet/tls |
| 171 | + readOnly: true |
| 172 | +``` |
| 173 | +
|
| 174 | +## Verify Kubelet Proxy |
| 175 | +
|
| 176 | +Assume that a module named `biz1-web-single-host` has been deployed and the Module Controller has enabled the Kubelet |
| 177 | +Proxy. |
| 178 | + |
| 179 | +``` |
| 180 | +NAME READY STATUS RESTARTS AGE |
| 181 | +base-76d79d8599-f64jt 1/1 Running 0 13d |
| 182 | +biz1-web-single-host-786dfc476f-qsp7q 1/1 Running 0 7m40s |
| 183 | +module-controller-59f7bb765-8w84l 1/1 Running 0 13d |
| 184 | +``` |
| 185 | +
|
| 186 | +At this point, you can directly access the module's logs using the kubectl command: |
| 187 | +
|
| 188 | +```bash |
| 189 | +kubectl logs --tail=50 biz1-web-single-host-786dfc476f-qsp7q |
| 190 | +``` |
| 191 | + |
| 192 | +It is expected to see normal log output. If an error occurs, it may indicate that the Kubelet Proxy is not properly |
| 193 | +configured or not enabled. |
0 commit comments