This article will show you how to interact with the Kubernetes API by creating Kubernetes deployments using a YAML file and deploy it on the Docker Desktop Kubernetes engine.
Kubernetes API and YAML Refrence
The Kubernetes API is a REST API that can create, configure and manage Kubernetes clusters. It’s most commonly used by the Kubernetes client (kubectl), which interacts with your Kubernetes cluster.
The Kubernetes API defines how to create containers or configure Kubernetes components like Kubernetes nodes. It uses various resources, like pods to deploy containers and replication controllers to run multiple instances of something (like a pod).
The Kubernetes API is the primary interface for Kubernetes clusters. This interface can be used by programs including kubectl, Kubernetes Dashboard and Kubernetes monitoring tools. Kubernetes can be used to deploy containers across a cluster of virtual machines or bare-metal deployments. Kubernetes manages the Kubernetes nodes that are running in your cluster.
An effective way to deploy an application into Kubernetes is using the Kubernetes YAML deployment. Below is an example of a deployment we use to deploy to our Docker desktop Kubernetes engine.
The YAML file configuration is taken from the Kubernetes API, which offers many configuration options. To add more configuration features, review the API and add settings as needed.
Below is a simple deployment that takes a Docker image I have built With a Dockerfile. You could also use a public image like nginx.
apiVersion: apps/v1 kind: Deployment metadata: name: strong-pass-app spec: selector: matchLabels: app: strongpassdotnet replicas: 1 template: metadata: labels: app: strongpassdotnet spec: containers: - name: strongpassdotnet image: strongpassdotnet ports: - containerPort: 80
Save and Run
To deploy the deployment, save the file as deployment.yaml and, using a command terminal open the folder the file is located and run the following command to deploy.
kubectl apply -f deplyment.yaml
To check the deployment run and make sure it is running run.
kubectl describe deployment strong-pass-app
To clean up and delete the deployment, run this command.
kubectl delete deployment strong-pass-app
The above example showed you how to get started and deploy a simple application to Kubernetes on Docker Desktop. Using Docker Desktop for testing Kubernetes compared to a public cloud deployment has a significant advantage, with the main one is cost.