Skip to content

Run cloud-provider-kind in cluster #336

@patrostkowski

Description

@patrostkowski

Currently, the documentation describes running cloud-provider-kind outside the cluster using Docker. Would it be possible to support running the cloud provider directly inside a Kind cluster as an optional configuration mode?

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
cloudProvider: true

I was able to get this working successfully by deploying the provider as a Deployment inside the cluster and mounting the host Docker socket (similar to the recommended Docker invocation).

Below is the setup I used.

Kind cluster config:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
    extraMounts:
      - hostPath: /var/run/docker.sock
        containerPath: /var/run/docker.sock

Deployment config:

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: cloud-provider-kind
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: cloud-provider-kind
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: cloud-provider-kind
    namespace: kube-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: cloud-provider-kind
  namespace: kube-system
  labels:
    k8s-app: cloud-provider-kind
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: cloud-provider-kind
  template:
    metadata:
      labels:
        k8s-app: cloud-provider-kind
    spec:
      serviceAccountName: cloud-provider-kind
      containers:
        - name: cloud-provider-kind
          image: registry.k8s.io/cloud-provider-kind/cloud-controller-manager:v0.10.0
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: docker-sock
              mountPath: /var/run/docker.sock
      volumes:
        - name: docker-sock
          hostPath:
            path: /var/run/docker.sock
            type: Socket

Result:

λ k apply -f deploy.yaml
serviceaccount/cloud-provider-kind unchanged
clusterrolebinding.rbac.authorization.k8s.io/cloud-provider-kind unchanged
deployment.apps/cloud-provider-kind configured
λ k get pods -n kube-system
NAME                                         READY   STATUS    RESTARTS   AGE
cloud-provider-kind-667dbfcdbf-769l9         1/1     Running   0          5m34s
coredns-674b8bbfcf-6rh96                     1/1     Running   0          7m14s
coredns-674b8bbfcf-p8cgf                     1/1     Running   0          7m14s
etcd-kind-control-plane                      1/1     Running   0          7m22s
kindnet-8dzzj                                1/1     Running   0          7m14s
kube-apiserver-kind-control-plane            1/1     Running   0          7m21s
kube-controller-manager-kind-control-plane   1/1     Running   0          7m21s
kube-proxy-6gdjl                             1/1     Running   0          7m14s
kube-scheduler-kind-control-plane            1/1     Running   0          7m22s
λ k create deployment --image nginx nginx
deployment.apps/nginx created
λ k expose deployment nginx --type LoadBalancer --port 80
service/nginx exposed
λ k get svc
NAME         TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP      10.96.0.1      <none>        443/TCP        9m43s
nginx        LoadBalancer   10.96.29.211   172.18.0.3    80:30495/TCP   8s
λ curl 172.18.0.3
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

I would be more than happy if someone could guide me on how to implement this so that I can contribute it myself 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions