Deploy EMQX Cluster in k8s with Restricted Access
Here we are assuming k8s cluster does not have access to the internet, and the user does not have permissions to create and/or use ClusterRole.
- Both
emqx-operatorandemqxare installed in the same namespace - The
emqx-operatoris configured to use a private docker registry, and theemqxis configured to use a customsecurityContext
Task Target
- Push necessary images to a private docker registry
- Manually install EMQX Operator CRDs
- Override default parameters of
emqx-operatorto use private registry, single namespace, and customsecurityContext - Use custom
securityContextfor EMQX
Push Necessary Docker Images to a Private Docker Registry
bash
export EMQX_OPERATOR_VERSION='3.0.0'
export EMQX_VERSION='5.10.0'
export REGISTRY='my.private.registry'
pull_retag_push() {
local source=$1
local target=$2
docker pull "$source"
docker tag "$source" "$target"
docker push "$target"
}
pull_retag_push "emqx/emqx-enterprise:$EMQX_VERSION" "$REGISTRY/emqx/emqx-enterprise:$EMQX_VERSION"
pull_retag_push "ghcr.io/emqx/emqx-operator:$EMQX_OPERATOR_VERSION" "$REGISTRY/emqx/emqx-operator:$EMQX_OPERATOR_VERSION"Deploy EMQX Operator
Deploy CRDs Manually from Release Assets
bash
kubectl -n emqx apply -f https://github.com/emqx/emqx-operator/releases/download/$EMQX_OPERATOR_VERSION/crds.yamlDeploy Emqx-Operator
In this example podSecurityContext and containerSecurityContext contain default values, override as necessary.
bash
helm repo add emqx https://repos.emqx.io/charts
helm repo update
helm upgrade --install emqx-operator emqx/emqx-operator \
--namespace emqx \
--create-namespace \
--set-json='watchNamespaces=["emqx"]' \
--set skipCRDs=true \
--set-json='podSecurityContext={"runAsNonRoot":true}' \
--set-json='containerSecurityContext={"allowPrivilegeEscalation":false}' \
--set image.repository=$REGISTRY/emqx/emqx-operator \
--set image.tag=$EMQX_OPERATOR_VERSIONEnsure emqx-operator is up and running:
bash
kubectl -n emqx wait --for=condition=Ready pods -l "control-plane=controller-manager"Configure EMQX Cluster
Save the following content as
emqx.yaml:yamlapiVersion: apps.emqx.io/v3beta1 kind: EMQX metadata: name: emqx namespace: emqx spec: image: ${REGISTRY}/emqx/emqx-enterprise:${EMQX_VERSION} config: roots: license: key: "..."Use
envsubstto substitute the environment variables exported earlier, and deploy the rendered manifest:bashenvsubst < emqx.yaml | kubectl apply -f -Wait for the EMQX cluster to be ready. You can check the status of the EMQX cluster through
kubectl getcommand. Make sureSTATUSisReady. This may take some time.bash$ kubectl get emqx emqx NAME STATUS AGE emqx Ready 10m