------------------ PODS -----------------------
Create a new pod with the nginx image.
kubectl run nginx --image=nginx
To check pods
kubeclt get pods
To describe pod - which image id its using, Which nodes are these pods placed on, how many container are running on the pods
kubectl describe pod newpods-nmsxl
Now change the image on this pod to redis. Make pod status to running state.
kubectl edit pod redis - edit the name of redis123 to redis
kubeclt get pods
If you used a pod definition file then update the image from redis123 to redis and then run kubectl apply command to update the image :-
kubectl apply -f redis-definition.yaml
To delete pod
kubectl delete pod webapp
------------------ REPLICA SETS -----------------------
How many ReplicaSets exist on the system?
kubectl get replicasets
Create a ReplicaSet using the replicaset-definition-1.yaml file located at /root/. There is an issue with the file, so try to fix it.
kubectl api-resources | grep replicaset
kubectl explain replicaset | grep VERSION
vi replicaset-definition-1.yaml - update the version
kubectl create -f /root/replicaset-definition-1.yaml
Fix the original replica set new-replica-set to use the correct busybox image.
kubectl edit replicaset new-replica-set kubectl get pods Delete the previous pods to get the new ones with the correct image. For this, run the command: kubectl delete po
Scale the ReplicaSet to 5 PODs.
kubectl edit replicaset new-replica-set OR kubectl scale rs new-replica-set --replicas=5
Delete any one of the 4 PODs.
kubectl delete pod
------------------ DEPLOYMENT -----------------------
To check deployment
kubectl get deployment
Edit and apply deployment
vi deployment-definition-1.yaml
kubectl apply -f deployment-definition-1.yaml
Create a new deployment- name=httpd-frontend, image=httpd:2.4-alpine, replicas=3
--- apiVersion: apps/v1 kind: Deployment metadata: name: httpd-frontend spec: replicas: 3 selector: matchLabels: name: httpd-frontend template: metadata: labels: name: httpd-frontend spec: containers: - name: httpd-frontend image: httpd:2.4-alpine
------------------ NAMESPACES ----------------------
To get namespaces
kubectl get ns
To check how many pods present in particular namespace
kubectl get pods -n research
To create namespace
kubectl create ns test
Create a POD in the finance namespace. Name=redis , image=redis
kubectl run redis --image=redis -n finance
------------------ SERVICES----------------------
To get service which are available
kubectl get svc
To know the target port
kubectl describe svc
Create a new service to access the web application using the service-definition-1.yaml file.
Name: webapp-service
Type: NodePort
targetPort: 8080
port: 8080
nodePort: 30080
selector:
name: simple-webapp
vi service-defintion-1.yaml
kubectl apply -f /root/service-definition-1.yaml
--------------- Imperative Commands --------------
Deploy a pod named nginx-pod using the nginx:alpine image.
kubectl run nginx-pod --image=nginx:alpine
Deploy a redis pod using the redis:alpine image with the labels set to tier=db.
kubectl run redis --image=redis:alpine -l tier=db
Create a service redis-service to expose the redis application within the cluster on port 6379.
kubectl expose pod redis --port=6379 --name=redis-service
Create a deployment named webapp using the image kodekloud/webapp-color with 3 replicas.
kubectl create deployment webapp --image=kodekloud/webapp-color --replicas=3
Create a new pod called custom-nginx using the nginx image and expose it on container port 8080.
kubectl run custom-nginx --image=nginx --port=8080
Create a new namespace called dev-ns.
kubectl create ns dev-ns
Create a new deployment called redis-deploy in the dev-ns namespace with the redis image. It should have 2 replicas.
kubectl create deployment redis-deploy --image=redis --replicas=2 -n dev-ns
Create a pod called httpd using the image httpd:alpine in the default namespace. Next, create a service of type ClusterIP by the same name (httpd). The target port for the service should be 80.
kubectl run httpd --image=httpd:alpine --port=80 --expose