0% found this document useful (0 votes)
8 views8 pages

Hello Minikube

The document provides a comprehensive guide on deploying and managing Kubernetes pods, replication controllers, replica sets, and deployments using various kubectl commands. It includes YAML configuration examples for creating and managing services, as well as instructions for scaling and updating deployments. Additionally, it covers service types and how to access services within a Kubernetes cluster.

Uploaded by

saiarungcp10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

Hello Minikube

The document provides a comprehensive guide on deploying and managing Kubernetes pods, replication controllers, replica sets, and deployments using various kubectl commands. It includes YAML configuration examples for creating and managing services, as well as instructions for scaling and updating deployments. Additionally, it covers service types and how to access services within a Kubernetes cluster.

Uploaded by

saiarungcp10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Deploys a pod or containerized application named hello-minikube in the cluster

Kubectl run hello-minikube

Displays details about the Kubernetes cluster and its control plane services.
Kubectl cluster-info

Lists all nodes in the cluster with their statuses and roles.
Kubectl get nodes

To create a pod and deploy an instance with the nginx image


Kubectl run nginx --image nginx

List all the pods in the cluster


Kubectl get pods

kubectl describe pod nginx

Kubectl get pods –o wide

vim pod.yaml

Example yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
tier: frontend
spec:
containers:
- name: nginx
image: nginx

cat pod.yaml

kubectl apply -f pod.yaml

To edit vim file


• vim myfile.txt
• Enter Insert Mode: i
• Type text.
• Save and quit: Esc → :wq → Enter.

-----------------------------------------------------------------------------------------------------
What is the flavor and version of Operating System on which the Kubernetes nodes are running?
kubectl get nodes -o wide

Create a new pod with the nginx image.


kubectl run nginx-pod --image=nginx

Which nodes are these pods are placed on?


Kubectl get pods –o wide

How many containers are part of the pod webapp?


Note: We just created a new POD. Ignore the state of the POD for now.
kubectl get pod webapp -o yaml

What is the state of the container agentx in the pod webapp?


Wait for it to finish the ContainerCreating state
kubectl get pod webapp –w

Why do you think the container agentx in pod webapp is in error?


Try to figure it out from the events section of the pod.
kubectl describe pod webapp

What does the READY column in the output of the kubectl get pods command indicate?
Running container in a pod/ total no of pod

Delete the webapp Pod.


kubectl delete pod webapp

Create a new pod with the name redis and the image redis123.
Use a pod-definition YAML file. And yes the image name is wrong!

apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis123 # Correct the image name if needed
ports:
- containerPort: 6379

Replication Controller
the replication controller creates multiple instances of a POD.

rc-definition.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc
labels:
app: myapp
tier: front-end
spec:
template:
metadata:
name: myapp-rc
labels:
app: myapp
tier: front-end
spec:
containers:
- name: nginx
image: nginx
replicas: 3

kubectl create -f rc-definition.yaml

kubectl get replicationcontroller

kubectl get pods

Replica Set
Replica set requires a selector definition. The selector section helps the replicaset identify what pods fall
under it.
replicaset-definition.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-rs
labels:
app: myapp
tier: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
tier: front-end
spec:
containers:
- name: nginx
image: nginx
replicas: 3
selector:
matchLabels:
type: front-end

To run the repicaset


Kubectl create -f replicationset-definition.yaml

To know the list of replicaset


Kubectl get replicaset
Kubectl get rs

Kubectl get pods

After any changes made in yaml file and update the replicaset
Kubectl replace -f replicationset-definition.yaml

To scale the replicasttion


Kubectl scale --replicas=6 -f replicationset-definition.yaml

Kubectl scale --replicas=6 replicaset myapp-rs-replicaset


| |
V V
Type name

To delete a replicaset
Kubectl delete replicaset myapp-rs-replicaset

• If any other pod made to run with the same selector label name, as it exceeds the required pod. so
it terminates the newly created pod.
• If a pod is deleted then a new pod is created . As to fullfill the required number of pod of replicaset

--------------------------------------------------------------------------------------------------
What is the image used to create the pods in the new-replica-set?
kubectl describe replicaset new-replica-set

How many PODs are READY in the new-replica-set?


kubectl get pods -l replicaset=new-replica-set

Why do you think the PODs are not ready?


kubectl describe pod new-replica-set-fqgds

Fix the original replica set new-replica-set to use the correct busybox image.
Either delete and recreate the ReplicaSet or Update the existing ReplicaSet and then delete all PODs, so
new ones with the correct image will be created.

Deployments

deployment-definition.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
type: front-end

Create
Kubectl create -f deployment-definition.yml

Get
Kubectl get deployments (k get deploy)
Kubectl get replicaset
Kubectl get pods (k get pods)
Kubectl get all

Status
Kubectl rollout status deployment/myapp-deployment
Kubectl rollout history deployment /myapp-deployment

Rolling update
Kubectl edit deploy
Kubectl set image deployment/myapp-deployment \nginx-container=nginx:1.9.1
Kubectl apply -f deployment-definition.yml

Rollback
Kubectl rollout undo deployment/myapp-deployment

Delete
Kubectl delete deployment myapp-deployment

-----------------------------------------------------------------------------------
Run the script named curl-test.sh to send multiple requests to test the web application. Take a note of
the output.
./curl-test.sh

Let us try that. Upgrade the application by setting the image on the deployment to kodekloud/webapp-
color:v2

kubectl edit deploy


k describe deploy frontend
k set image deploy frontend simple-webapp=kodekloud/webapp-color:v2
k describe deploy frontend
./curl-test.sh

Change the deployment strategy to RecreateDelete and re-create the deployment if necessary. Only
update the strategy type for the existing deployment.

------------------------------------------------------------
Services
1.nodeport- were the service makes an internal POD accessible on a Port on the Node
2.cluster IP - the service creates a virtual IP inside the cluster to enable communication between
different services such as a set of front-end servers to a set of backend service
3.Loadbalancer - distribute load across different web servers

Service-definition.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp-service
Spec:
type: NodePort/ClusterIP/LoadBalancer
ports:
- targetPort: 80
port: 80
nodePort: 30008
selector:
app: myapp
type: front-end

pod-definition.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
Image: nginx

---------------------------------------------------------------------------------
How many Services exist on the system?
kubectl get svc

Minikube service myapp-service –url

What is the targetPort configured on the kubernetes service?


kubectl describe service kubernetes

You might also like