/ldap-accounts-controller

Sample code on creating a Kubernetes Operator using kubebuilder

Primary LanguageGoApache License 2.0Apache-2.0

Kubernetes Controller for OpenLDAP accounts

⚠️ This is just a learning exercise, not for real use

What is this?

This is just a learning exercise for me on using Operator. This code assumes you have an OpenLDAP server running in Kubernetes using the standard posixAccount. You can then use a simple yaml to create and delete users.

apiVersion: ldap.digitalis.io/v1
kind: LdapUser
metadata:
  name: user01
spec:
  username: user01
  password: letmein
  gid: "1000"
  uid: "1000"
  homedir: /home/user01
  shell: /bin/bash

Running

You can run it from command line using something like:

LDAP_BASE_DN="dc=digitalis,dc=io" \
LDAP_BIND="cn=admin,dc=digitalis,dc=io" \
LDAP_PASSWORD=xxxx \
LDAP_HOSTNAME=ldap_server_ip_or_host \
LDAP_PORT=389 \
LDAP_TLS="false" \
make install run

Optinally you can also add the patch for SSL cert and key with

LDAP_TLS_CERT=path
LDAP_TLS_KEY=path
LDAP_TLS_CA=path

Check out kubebuilder docs on creating your own docker image to use inside kubernetes or which you can see an extract in the section below:

https://book.kubebuilder.io/quick-start.html#run-it-on-the-cluster

Docker build

To deploy into a kubernetes you'll need to first create a docker image and push it to a registry from where k8s can download it. You can use for this:

make docker-build docker-push IMG=<some-registry>/<project-name>:tag

and after this you can deploy it with

make deploy IMG=<some-registry>/<project-name>:tag

Sample

OpenLDAP Controller