Skip to content

Using kubectl

Create ConfigMap from config files

A ConfigMap stores K8s-specific configuration that can be mounted as volume or used in env variables. It is often used to provide production configuration: application configuration, log settings, etc...

kubectl create configmap app-conf --from-file=<path to config files>  # create a ConfigMap from multiple files in the same directory.
  • Check the ConfigMap
kubectl get configmap app-conf -o yaml

# or

kubectl describe configmaps app-conf

Create a Kubernetes secret

You may need a Secret to store database passwords and secret keys.

For applications using the Play Framework, generate a secret using:

secretText = $(sbt playGenerateSecret)
regex = "Generated new secret: (.+)$"
f [[ $secretText =~ $regex ]]
    then
        secret = "${BASH_REMATCH[1]}"
        echo $secret
        kubectl create secret generic application-secret --from-literal=application_secret=$secret
        kubectl get secrets
    else
        echo "$secretText doesn't match" >&2
    fi
done

Create Resources (Deployment, Service, Ingress, etc...)

kubectl create -f <path/to/resource_config.yaml>
  • Verify proper resource creation
kubectl get ing
kubectl get service
kubectl get deployment
kubectl get pods
  • To delete a resource later, in this case a Deployment:
kubectl delete deployment <deployment name>

Install an Ingress Controller

  • An ingress controller is necessary to make Ingresses work. See the Ingress doc

Minikube

  • minikube provides its own ingress controller via the Ingress add-on:
minikube addons enable ingress

Enabling the add-on provisions the following:

  • a configMap for the Nginx loadbalancer
  • the Nginx ingress controller
  • a service that exposes a default Nginx backend pod for handling unmapped requests.

Alternative ingress controllers

Declarative Deployments (Kustomize)

Kustomize is built into kubectl and allows for template-free customization of YAML manifests.

To deploy a directory containing a kustomization.yaml file:

kubectl apply -k <directory-path>

To view the generated native manifests without applying them:

kubectl kustomize <directory-path>