What you will learn:
In this tutorial you will learn:
- Introduction to kubernetes using the simple .net core api image from docker container registry
- Basic nderstanding of deployment and service yaml file in kubernetes.
- Using minikube
Kubernetes Service and Deployment are two fundamental components of the Kubernetes ecosystem.
The Service acts as the gateway for communication and load balancing. On the other hand, Deployment orchestrates the management and scaling of your application’s replicas.
apiVersion: apps/v1
kind: Deployment
metadata:
name: simple-core-api-deployment
spec:
replicas: 3
selector:
matchLabels:
app: simple-core-api
template:
metadata:
labels:
app: simple-core-api
spec:
containers:
- name: simple-core-api
image: sandboxdaily/simplecoreapi:1.0.0
imagePullPolicy: Always
ports:
- containerPort: 80
$ kubectl apply -f deploy.yml
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
demo-app 1/1 Running 4 (22h ago) 13d
simple-core-api-deployment-69bdc96c97-6nj6b 1/1 Running 4 (22h ago) 13d
simple-core-api-deployment-69bdc96c97-kf42t 1/1 Running 4 (22h ago) 13d
simple-core-api-deployment-69bdc96c97-m5mf7 1/1 Running 4 (22h ago) 13d
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
simple-core-api-deployment 3/3 3 3 11d
Note: if kubectl apply -f deploy.yml doesn’t work, run this in console: $ minikube start (see below about minikube)
# https://kubernetes.io/docs/concepts/services-networking/service/
apiVersion: v1
kind: Service
metadata:
name: simple-core-api
spec:
selector:
app: simple-core-api
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
$ kubectl apply -f service.yml
$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 11d
simple-core-api LoadBalancer 10.104.243.171 127.0.0.1 80:30804/TCP 11d
$ curl http://127.0.0.1/api/values
{"machineName":"simple-core-api-deployment-69bdc96c97-kf42t","environment":null,"logJsonPath":"payloads-base"}
Note: if the api is not working, run this in console: $ minikube tunnel (see below about minikube)
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
demo-app 1/1 Running 4 (23h ago) 13d
simple-core-api-deployment-69bdc96c97-6nj6b 1/1 Running 4 (23h ago) 13d
simple-core-api-deployment-69bdc96c97-kf42t 1/1 Running 4 (23h ago) 13d
simple-core-api-deployment-69bdc96c97-m5mf7 1/1 Running 4 (23h ago) 13d
$ kubectl delete pod simple-core-api-deployment-69bdc96c97-6nj6b
pod "simple-core-api-deployment-69bdc96c97-6nj6b" deleted
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
demo-app 1/1 Running 4 (23h ago) 13d
simple-core-api-deployment-69bdc96c97-kf42t 1/1 Running 4 (23h ago) 13d
simple-core-api-deployment-69bdc96c97-m5mf7 1/1 Running 4 (23h ago) 13d
simple-core-api-deployment-69bdc96c97-xcr9j 0/1 ContainerCreating 0 2s
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
demo-app 1/1 Running 4 (23h ago) 13d
simple-core-api-deployment-69bdc96c97-kf42t 1/1 Running 4 (23h ago) 13d
simple-core-api-deployment-69bdc96c97-m5mf7 1/1 Running 4 (23h ago) 13d
simple-core-api-deployment-69bdc96c97-xcr9j 1/1 Running 0 69s
What is minikube?
Minikube is a lightweight and simplified version of Kubernetes, primarily used for local development and testing purposes.
What is minikube used for?
You can use Minikube to learn how to deploy and manage applications in Kubernetes.
Minikube can be used to develop Kubernetes applications and test your applications before deploying them to production.
What is the difference between Kubernetes and minikube?
On the Deployment Scale: Kubernetes is designed for large-scale deployments across multiple nodes and clusters, making it suitable for managing complex and distributed environments. On the other hand, Minikube is a lightweight and simplified version of Kubernetes, suitable for local development and testing purposes.
$ minikube start
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ You are trying to run the amd64 binary on an M1 system. │
│ Please consider running the darwin/arm64 binary instead. │
│ Download at https://github.com/kubernetes/minikube/releases/download/v1.32.0/minikube-darwin-arm64 │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
😄 minikube v1.32.0 on Darwin 14.5
🎉 minikube 1.34.0 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.34.0
💡 To disable this notice, run: 'minikube config set WantUpdateNotification false'
✨ Using the docker driver based on existing profile
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image ...
🔄 Restarting existing docker container for "minikube" ...
🐳 Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...
🔗 Configuring bridge CNI (Container Networking Interface) ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
$ minikube tunnel
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ You are trying to run the amd64 binary on an M1 system. │
│ Please consider running the darwin/arm64 binary instead. │
│ Download at https://github.com/kubernetes/minikube/releases/download/v1.32.0/minikube-darwin-arm64 │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────╯
✅ Tunnel successfully started
📌 NOTE: Please do not close this terminal as this process must stay alive for the tunnel to be accessible ...
❗ The service/ingress simple-core-api requires privileged ports to be exposed: [80]
🔑 sudo permission will be asked for it.
🏃 Starting tunnel for service simple-core-api.
Password:
Related topics: Dockerize Simple .Net Core API , Build and Push Docker images to Docker hub registry
References:
docker image: https://hub.docker.com/repository/docker/sandboxdaily/simplecoreapi/general