Hello Minikube
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
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
-----------------------------------------------------------------------------------------------------
What is the flavor and version of Operating System on which the Kubernetes nodes are running?
kubectl get nodes -o wide
What does the READY column in the output of the kubectl get pods command indicate?
Running container in a pod/ total no of pod
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
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
After any changes made in yaml file and update the replicaset
Kubectl replace -f replicationset-definition.yaml
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
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
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