-
Write Kubernetes yaml file to deploy a sample app (You can use any publicly available app as deployment image) & make sure: a. App is highly available. b. App/Pods can be updated in rollout manner.
-
Signup to killercode
-
install docker if not installed already
-
open vi write a kubernetes file.
yaml # deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: sample-app spec: replicas: 3 # Adjust the number of replicas based on your high availability requirements selector: matchLabels: app: sample-app template: metadata: labels: app: sample-app spec: containers: - name: sample-app image: nginx:latest # Replace with your desired publicly available app image ports: - containerPort: 80 strategy: rollingUpdate: maxSurge: 1 maxUnavailable: 1 type: RollingUpdate
apt-get update
kubectl get nodes
kubectl version
-
This YAML file defines a Kubernetes Deployment with three replicas, ensuring high availability. The rollingUpdate strategy ensures that during a deployment update, only one new pod is created at a time (maxSurge: 1), and at least one old pod is available (maxUnavailable: 1), making the update process gradual and minimizing downtime.
-
Make sure to replace nginx:latest with the actual image of the publicly available app you want to deploy.
-
Apply the YAML file using the kubectl apply command:
# bash kubectl apply -f deployment.yaml
-
This will create the deployment and the necessary pods for your sample app, ensuring high availability and supporting rolling updates.
-
deployments detail
kubectl get deployments
-
get nodes
kubectl get nodes
-
describe deployment sample-app
kubectl describe deployment sample-app
-
describe pods
kubectl describe pods
-
describe pod and app
kubectl get pods -l app=sample-app
-
describe pod apps 1,2,3
kubectl describe pod sample-app-587d9c6687-2gk8r
kubectl describe pod sample-app-587d9c6687-7cgft
kubectl describe pod sample-app-587d9c6687-cxz4h
- All the above process is same part from installation
- install docker & minikube
- install the latest minikube stable release on x86-64 Linux using Debian package: minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb
- From a terminal with administrator access (but not logged in as root), run:
minikube start
-
Interact with your cluster
kubectl get po -A
minikube kubectl -- get po -A
alias kubectl="minikube kubectl --"
minikube dashboard
-
Deploy applications
-
Create a sample deployment and expose it on port 8080:
kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0 kubectl expose deployment hello-minikube --type=NodePort --port=8080
*OR(We have deployed two applications named as hello-minikubes & sample-app)*
-
open vi write a kubernetes file.
yaml
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-app
spec:
replicas: 3 # Adjust the number of replicas based on your high availability requirements
selector:
matchLabels:
app: sample-app
template:
metadata:
labels:
app: sample-app
spec:
containers:
- name: sample-app
image: nginx:latest # Replace with your desired publicly available app image
ports:
- containerPort: 80
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
- Let’s break each line down…
- apiVersion: Specifies the Kubernetes API version. In this case, it’s using the “apps/v1” API version, which is appropriate for Deployments.
- kind: Specifies the type of Kubernetes resource. Here, it’s “Deployment,” indicating that this configuration file is defining a Deployment.
- spec: This section defines the desired state of the Deployment.
- replicas: 3: Specifies that you want to run three replicas of your application.
- selector: Describes the selector to match pods managed by this Deployment.
- matchLabels: Specifies the labels that the Replica Set created by the Deployment should use to select the pods it manages. In this case, pods with the label app: sample-app are selected.
- template: Defines the pod template used for creating new pods.
- metadata: Contains the labels to apply to the pods created from this template. In this case, the pods will have the label
- app: sample-app.
- spec: Describes the specification of the pods.
- containers: This section specifies the containers to run in the pod.
- name: sample-app: Assigns a name to the container.
- image: example-image: Specifies the Docker image to use for this container.
- ports: Defines the ports to open in the container.
- containerPort: 8080: Indicates that the container will listen on port 80.
-
Apply the YAML file using the kubectl apply command:
kubectl apply -f deployment.yaml
-
It may take a moment, but your deployment will soon show up when you run:
kubectl get services
-
The easiest way to access this service is to let minikube launch a web browser for you:
minikube service --all
-
manage your cluster
-
Pause Kubernetes without impacting deployed applications:
minikube pause
-
Unpause a paused instance:
minikube unpause
-
Halt the cluster:/ stop
minikube stop
- Browse the catalog of easily installed Kubernetes services:
minikube addons list
-
Create a second cluster running an older Kubernetes release:
minikube start -p aged --kubernetes-version=v1.16.1
-
Delete Deployments - Delete all of the minikube clusters:
****