diff --git a/Commands and args/README.md b/Commands and args/README.md new file mode 100644 index 0000000..42a862a --- /dev/null +++ b/Commands and args/README.md @@ -0,0 +1,22 @@ +# Commands and Arguments in Kubernetes + +This readme file provides information and practical examples regarding the usage of commands and arguments in Kubernetes. + +## Create a Pod with Commands and Arguments +- To create a pod named demo-pod with the Debian image and use the printenv HOSTNAME command: +``` +kubectl run demo-pod --image=debian --command -- printenv HOSTNAME +``` + +## Apply YAML File and Checking Pod Status +To apply a YAML file and check the status of the pod: +``` +kubectl apply -f your-file.yaml +kubectl get pod -o wide +``` + +## Verify Hostname in Pod Logs +To verify the hostname is printed in the logs of a pod, use the following commands: +``` +kubectl logs demo-pod +``` diff --git a/Custom-Scheduler/README.md b/Custom-Scheduler/README.md new file mode 100644 index 0000000..7e4777b --- /dev/null +++ b/Custom-Scheduler/README.md @@ -0,0 +1,158 @@ +# Steps to Implement Custom Scheduler +The following steps outline the process of creating a custom scheduler as a pod and using it to schedule an Nginx pod. Follow these steps to set up the custom scheduler: + +- Copy the Kube-scheduler.yaml located under the /etc/kubernetes/manifests/ directory to my-scheduler.yaml file outside the /etc/kubernetes/manifests/ directory and update the my-scheduler.yaml file as mentioned in the following steps: + +- Change the name under the metadata section to "my-scheduler" and create the pod under the default namespace. +``` +apiVersion: v1 +kind: Pod +metadata: + labels: + component: my-scheduler + tier: control-plane + name: my-scheduler +``` + +- Update the command field in the spec section by setting --leader-elect=false. This is because you only have a single master node in the cluster. If there were multiple master nodes, you would choose --leader-elect=true. +``` +spec: + containers: + - command: + - kube-scheduler + - --authentication-kubeconfig=/etc/kubernetes/scheduler.conf + - --authorization-kubeconfig=/etc/kubernetes/scheduler.conf + - --bind-address=127.0.0.1 + - --kubeconfig=/etc/kubernetes/scheduler.conf + - --leader-elect=false +``` + +- Find an available port to bind to the pod. You can use the following command to check for free port numbers: +``` +netstat -natulp | grep 10282 +``` + +- Set the --scheduler-name property and assign the desired name for your custom scheduler. For example, if you want to name it "my-scheduler": +``` +- --port=10282 +- --scheduler-name=my-scheduler +- --secure-port=0 +``` + +- Leave other configurations as they are and change the port number in the livenessProbe section to port: 10282. +``` +livenessProbe: + failureThreshold: 8 + httpGet: + host: 127.0.0.1 + path: /healthz + port: 10282 +``` + +- The final YAML file should look like the following: +``` +apiVersion: v1 +kind: Pod +metadata: + labels: + component: my-scheduler + tier: control-plane + name: my-scheduler +spec: + containers: + - command: + - kube-scheduler + - --authentication-kubeconfig=/etc/kubernetes/scheduler.conf + - --authorization-kubeconfig=/etc/kubernetes/scheduler.conf + - --bind-address=127.0.0.1 + - --kubeconfig=/etc/kubernetes/scheduler.conf + - --leader-elect=false + - --port=10282 + - --scheduler-name=my-scheduler + - --secure-port=0 + image: k8s.gcr.io/kube-scheduler:v1.19.0 + imagePullPolicy: IfNotPresent + livenessProbe: + failureThreshold: 8 + httpGet: + host: 127.0.0.1 + path: /healthz + port: 10282 + scheme: HTTP + initialDelaySeconds: 10 + periodSeconds: 10 + timeoutSeconds: 15 + name: kube-scheduler + resources: + requests: + cpu: 100m + startupProbe: + failureThreshold: 24 + httpGet: + host: 127.0.0.1 + path: /healthz + port: 10282 + scheme: HTTP + initialDelaySeconds: 10 + periodSeconds: 10 + timeoutSeconds: 15 + volumeMounts: + - mountPath: /etc/kubernetes/scheduler.conf + name: kubeconfig + readOnly: true + hostNetwork: true + priorityClassName: system-node-critical + volumes: + - hostPath: + path: /etc/kubernetes/scheduler.conf + type: FileOrCreate + name: kubeconfig +status: {} +``` + +- Save the my-scheduler.yaml file and create the pod using the following command: +``` +kubectl apply -f my-scheduler.yaml +``` + +- This will create a custom scheduler pod in the default namespace. You can verify its creation by running the command: +``` +kubectl get pods +``` + +- Create a pod YAML file and specify the schedulerName option as "my-scheduler" to instruct Kubernetes to use your custom scheduler for this pod. The YAML file should look like this: +``` +apiVersion: v1 +kind: Pod +metadata: + name: mypod + labels: + name: multischeduler +spec: + schedulerName: my-scheduler + containers: + - name: nginx + image: nginx +``` + +- Verify whether your custom scheduler is used by checking the events section of the pod. Use the following command: +``` +kubectl describe pod mypod +``` + +- Look for the Events section and check the output. You should see an event indicating that the pod was successfully assigned to the custom scheduler: +``` +Events: + Type Reason Age From Message + ---- ------ ---- ---- ------- + Normal Scheduled 16m my-scheduler Successfully assigned mypod to minikube + Normal Pulling 16m kubelet, minikube Pulling image "nginx" + Normal Pulled 16m kubelet, minikube Successfully pulled image "nginx" + Normal Created 16m kubelet, minikube Created container nginx + Normal Started 16m kubelet, minikube Started container nginx +``` + +- Congratulations! You have successfully created a custom scheduler and used it to schedule a pod. + +## Conclusion: +This guide covered the implementation steps for creating a custom scheduler in Kubernetes. It explained the process of creating a custom scheduler pod, configuring its parameters, and using it to schedule a specific pod. By following these steps, you have gained insights into how the scheduler works and how to leverage custom scheduling in Kubernetes. diff --git a/DaemonSet/README.md b/DaemonSet/README.md new file mode 100644 index 0000000..d398ebf --- /dev/null +++ b/DaemonSet/README.md @@ -0,0 +1,76 @@ +# Daemonsets in Kubernetes +This README file provides an overview of Daemonsets in Kubernetes, including their creation, rolling updates, rollback, viewing running Daemonsets, and deleting Daemonsets. + +## Create a Daemonset +- To create a Daemonset in Kubernetes use the following yaml file: +``` +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: fluentd-daemonset +spec: + selector: + matchLabels: + app: fluentd + template: + metadata: + labels: + app: fluentd + spec: + containers: + - name: fluentd + image: fluent/fluentd:latest +``` +- Apply above file using command: +``` +kubectl apply -f fluentd-daemonset.yaml +``` + +- To view all the running Daemonsets, use the following command: +``` +kubectl get daemonsets +``` + +## Update a Daemonset +- Update fluentd-daemonset.yaml: +``` +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: fluentd-daemonset +spec: + selector: + matchLabels: + app: fluentd + template: + metadata: + labels: + app: fluentd + spec: + containers: + - name: fluentd + image: fluent/fluentd:v1.2.3 +``` + +## View upadted daemonset's pod +``` +kubectl get pods -l app=fluentd +``` + +## Check logs collected by fluentd +Once you have the pod name, you can view the logs by running the following command: +``` +kubectl logs +``` + +## Rolling Update a Daemonset +- To rollback the Daemonset to a previous version, use the following command: +``` +kubectl rollout undo daemonset fluentd-daemonset +``` + +## Delete a Daemonset +To delete the Daemonset named "fluentd-daemonset", use the following command: +``` +kubectl delete daemonset fluentd-daemonset +``` diff --git a/Deployment/README.md b/Deployment/README.md new file mode 100644 index 0000000..8934e31 --- /dev/null +++ b/Deployment/README.md @@ -0,0 +1,42 @@ +# Deployment Creation +This README file provides step-by-step instructions to perform various deployment operations using Kubernetes. The following practical questions are covered in this guide. + +Video Link: https://youtu.be/-uO400iEuKo + +### Question 1: Create a deployment named my-deploy with the image nginx. +To create a deployment named "my-deploy" with the nginx image, use the following command: +``` +kubectl create deployment my-deploy --image=nginx +``` + +### Question 2: Scale my-deploy to 3 replicas. +To scale the "my-deploy" deployment to 3 replicas, use the following command: +``` +kubectl scale deployment my-deploy --replicas=3 +``` + +### Question 3: Replace the image in my-deploy from nginx to nginx:alpine. +To replace the image in the "my-deploy" deployment from "nginx" to "nginx:alpine", use the following command: +``` +kubectl set image deployment my-deploy nginx=nginx:alpine +``` + +### Question 4: Scale down the replicas of my-deploy to 2. +To scale down the replicas of the "my-deploy" deployment to 2, use the following command: +``` +kubectl scale deployment my-deploy --replicas=2 +``` + +### Question 5: Rollback to the previous version of my-deploy. +To rollback the "my-deploy" deployment to the previous version, use the following command: +``` +kubectl rollout undo deployment my-deploy +``` + +### Question 6: Delete the deployment, replicaset, and pod created by my-deploy. +To delete the deployment, replicaset, and pods created by the "my-deploy" deployment, use the following command: +``` +kubectl delete deployment my-deploy +``` + +That's it! You've learned how to perform various deployment operations in Kubernetes. For a visual demonstration, refer to the video link provided above. diff --git a/Namespace/README.md b/Namespace/README.md new file mode 100644 index 0000000..091fa50 --- /dev/null +++ b/Namespace/README.md @@ -0,0 +1,30 @@ +# Namespace Creation + +## Introduction +This README file provides a step-by-step guide to performing practical tasks related to Namespace creation in Kubernetes. The questions covered in this guide will help you understand and practice creating namespaces and working with pods within those namespaces. + +Link to YouTube Video: https://youtu.be/dBjWCOwcTvM + +### Question 1: Create a namespace named "my-first-ns". +``` +kubectl create namespace my-first-ns +``` +This will create a new namespace called "my-first-ns" in your Kubernetes cluster. + +### Question 2: Create a pod named "red" with the image "nginx" within the "my-first-ns" namespace. +``` +kubectl create pod red --image=nginx --namespace=my-first-ns +``` +This will create a pod named "red" with the nginx image specifically within the "my-first-ns" namespace. + +### Question 3: Count all the pods across all namespaces +``` +kubectl get pods --all-namespaces --no-headers | wc -l +``` +This will provide the count of all the pods present in all namespaces in your Kubernetes cluster. + +### Question 4: Permanently switch the namespace to "my-first-ns" +``` +kubectl config set-context --current --namespace=my-first-ns +``` +This will set the namespace to "my-first-ns" as the default namespace for all subsequent commands. diff --git a/NodeSelector/README.md b/NodeSelector/README.md new file mode 100644 index 0000000..ec6e8f8 --- /dev/null +++ b/NodeSelector/README.md @@ -0,0 +1,51 @@ +# NodeSelector in Kubernetes +This readme provides a quick recap of NodeSelector in Kubernetes, including practical examples and questions. + +## Practical Questions and Answers +### Question 1: Label the node with key=capacity and value=low +To label a node with the key "capacity" and value "low," use the following command: +``` +kubectl label nodes capacity=low +``` + +### Question 2: Create a pod and use NodeSelector to schedule it onto the labeled node +To create a pod and schedule it onto a labeled node using NodeSelector, follow these steps: + +- Create a YAML file with the following content: +``` +apiVersion: v1 +kind: Pod +metadata: + name: my-pod +spec: + containers: + - name: my-container + image: my-image + nodeSelector: + capacity: low +``` + +- Apply the YAML file using the following command: +``` +kubectl apply -f pod.yaml +``` + +## Additional Commands +- To verify the node labels, use the following command: +``` +kubectl get node --show-labels +``` +This command will display a list of nodes along with their labels. + +## Additional Practical Questions +### Question1 : Label all nodes in your Kubernetes cluster with a key-value pair "environment=production". +To label all nodes with the key-value pair "environment=production" use the following command: +``` +kubectl label nodes --all environment=production +``` + +### Question2 : How can you remove a label from a node? +To remove a label from a node use the kubectl label command with the key and node name. For example: +``` +kubectl label node capacity- +``` diff --git a/Nodename/README.md b/Nodename/README.md new file mode 100644 index 0000000..7ce9b37 --- /dev/null +++ b/Nodename/README.md @@ -0,0 +1,65 @@ +# Kubernetes Manual Scheduling using nodename Property + +## Introduction +This readme file provides instructions on manually scheduling Kubernetes pods using the nodename property. Please refer to the following YouTube video for a practical demonstration of the concepts discussed in this readme: + +YouTube Video: [Manual Scheduling in Kubernetes](https://youtu.be/ARHfMpiBv-4) + +### Question 1: Create a pod named mypod and manually schedule it onto the master node. +- Create a file named mypod.yaml. +``` +apiVersion: v1 +kind: Pod +metadata: + name: mypod + labels: + color: blue +spec: + nodeName: master + containers: + - name: mycontainer + image: nginx +``` + +- Apply the pod manifest using the following command: +``` +kubectl apply -f mypod.yaml +``` + +- To check the node where mypod is scheduled, you can use the following command: +``` +kubectl get pods mypod -o wide +``` + +This command will provide detailed information about the mypod, including the node it is scheduled on. + +### Question 2: Reschedule the mypod pod onto the worker-1 node. + +- Edit the mypod.yaml file and change the nodeName property to the following: +``` +nodeName: worker-1 +``` + +- Apply the modified pod manifest using the following command: +``` +kubectl apply -f mypod.yaml +``` + +- To check the node where mypod is scheduled, you can use the following command: +``` +kubectl get pods mypod -o wide +``` + +### Question 3: Create two pods and label them with the label color: blue imperatively + +- Run the following command to create the first and second pod: +``` +kubectl run first-pod --image=nginx --labels=color=blue +kubectl run second-pod --image=nginx --labels=color=blue +``` + +### Question 4: Select all pods with the label color: blue using the selector keyword. +- Run the following command to select the pods with label color: blue. +``` +kubectl get pods --selector=color=blue +``` diff --git a/Pod/Declarative Way/README.md b/Pod/Declarative Way/README.md new file mode 100644 index 0000000..3282030 --- /dev/null +++ b/Pod/Declarative Way/README.md @@ -0,0 +1,49 @@ +# Practical Questions on Pod Creation + +## Introduction +This readme file provides step-by-step instructions for the practical questions on pod creation covered in the YouTube video [https://youtu.be/1ljs7rUGsJM]. Each question focuses on a specific task related to creating and managing pods using Kubernetes. Follow the instructions below to perform each task and gain hands-on experience with pod creation. + +### Question 1: Create a Pod with Image Nginx using Declarative Way +Create a YAML file named pod.yaml with the following content: + +``` +apiVersion: v1 +kind: Pod +metadata: + name: mypod +spec: + containers: + - name: my-first-container + image: nginx +``` + +- Apply the YAML file using the command: +``` +kubectl apply -f pod.yaml +``` +- Check the state of the Pod using: +``` +kubectl get po +``` + +### Question 2: Replace the Image of the Pod from Nginx to Busybox +To replace the image of the pod from Nginx to Busybox, modify the pod.yaml file, changing the image field to busybox. Then, apply the changes by running the same command used in Question 1: +``` +kubectl apply -f pod.yaml +``` + +### Question 3: Check the Status of the Pod +To check the status of the pod, use the following command: +``` +kubectl get po +``` + +This command will display the current state and details of all pods in the cluster. + +### Question 4: Delete the Pod +To delete the pod, use the following command: +``` +kubectl delete pod mypod +``` + +This command will remove the specified pod named mypod from the cluster. diff --git a/Pod/Imperative Way/README.md b/Pod/Imperative Way/README.md new file mode 100644 index 0000000..6bf675c --- /dev/null +++ b/Pod/Imperative Way/README.md @@ -0,0 +1,25 @@ +# Pod Creation using Imperative Way + +## Introduction +This readme file provides step-by-step instructions for the practical questions on pod creation using the imperative way. These questions were covered in the YouTube video [https://youtu.be/ODJwFsdK2oU]. Each question focuses on a specific task related to creating pods using imperative commands in Kubernetes. Follow the instructions below to perform each task and gain hands-on experience with pod creation. + +### Question 1: Create a pod with name "mypod" using nginx:alpine image. +To create a pod with the name "mypod" and using the nginx:alpine image, use the following command: +``` +kubectl run mypod --image=nginx:alpine +``` +This command will create the pod with the specified name and image. + +### Question 2: Create a pod with name "pod-2" using the redis image with label name=pod-2 +To create a pod named "pod-2" using the Redis image and assigning the label "name=pod-2", use the following command: +``` +kubectl run pod-2 --image=redis --labels=name=pod-2 +``` +This command will create the pod with the specified name, image, and label. + +### Question 3: Create a pod with name "nginx" and image nginx, expose it on Port 8080 +To create a pod with the name "nginx" using the nginx image and expose it on port 8080, use the following command: +``` +kubectl run nginx --image=nginx --port=8080 +``` +This command will create the pod with the specified name, image, and port. diff --git a/ReplicaSet/README.md b/ReplicaSet/README.md new file mode 100644 index 0000000..2e361ed --- /dev/null +++ b/ReplicaSet/README.md @@ -0,0 +1,61 @@ +# Replicaset Creation + +## Introduction +This README provides a step-by-step guide to create and manage a Replicaset in Kubernetes. It covers the creation of a Replicaset using the declarative approach, scaling the Replicaset imperatively, deleting a pod from the Replicaset, and finally, deleting the entire Replicaset. + +The instructions mentioned in this readme are based on a practical demonstration given in the following YouTube video: [Link to Video](https://youtu.be/ODJwFsdK2oU). + +### Question 1: Create a Replicaset with 1 replica +To create a Replicaset named "myfirstrs" with the Nginx image and 1 replica using the declarative way, follow these steps: + +- Create a YAML file, e.g., myfirstrs.yaml. +- Open the file and add the following YAML content: +``` +apiVersion: apps/v1 +kind: ReplicaSet +metadata: + name: myfirstrs +spec: + replicas: 1 + selector: + matchLabels: + app: myfirstrs + template: + metadata: + labels: + app: myfirstrs + spec: + containers: + - name: nginx + image: nginx +``` + +- Save the file and apply the configuration using the following command: +``` +kubectl apply -f myfirstrs.yaml +``` + +### Question 2: Scale the Replicaset to 5 pods +To scale the Replicaset named "myfirstrs" to 5 pods using the imperative way, execute the following command: +``` +kubectl scale replicaset myfirstrs --replicas=5 +``` + +### Question 3: Delete one of the pods +To delete one of the pods from the Replicaset, you can choose any of the pods in the Replicaset and delete it manually. Use the following command to list the pods: +``` +kubectl get pods +``` + +- Once you have identified the pod you want to delete, use the following command: +``` +kubectl delete pod +``` +- Replace with the name of the pod you wish to delete. + +### Question 4: Delete the Replicaset +To delete the entire Replicaset named "myfirstrs," execute the following command: +``` +kubectl delete replicaset myfirstrs +``` +This command will delete the Replicaset and all associated pods. diff --git a/Resource Quota/README.md b/Resource Quota/README.md new file mode 100644 index 0000000..9c1df56 --- /dev/null +++ b/Resource Quota/README.md @@ -0,0 +1,54 @@ +# Resource Quota Creation + +## Introduction +This README provides instructions on how to create, verify, view, and delete Resource Quotas in Kubernetes using YAML files. It also explains how to check the resource utilization of a specific namespace. The steps mentioned below can be followed to perform these operations. + +Video Link: https://youtu.be/nia8nreVmBg + +## Creating a Resource Quota +Create a YAML file, for example, resource-quota.yaml, with the desired specifications for the Resource Quota. +``` +apiVersion: v1 +kind: ResourceQuota +metadata: + name: compute-resources + namespace: my-first-ns +spec: + hard: + pods: "4" + requests.cpu: "1" + requests.memory: 1Gi + limits.cpu: "2" + limits.memory: 2Gi +``` + +Apply the Resource Quota using the following command: +``` +kubectl apply -f resource-quota.yaml +``` + +## Verify Resource Quota Creation +To verify that the Resource Quota has been successfully created, run the following command: +``` +kubectl get resourcequota compute-resources -n my-first-ns +``` + +## View Existing Resource Quotas +To view the existing Resource Quotas in the my-first-ns namespace, use the following command: +``` +kubectl get resourcequota -n my-first-ns +``` + +## Delete a Resource Quota +To delete a Resource Quota from the my-first-ns namespace, execute the following command: +``` +kubectl delete resourcequota compute-resources -n my-first-ns +``` + +## Checking Resource Utilization +To check the resource utilization of the my-first-ns namespace, run the following command: +``` +kubectl top namespace my-first-ns +``` + +For more detailed explanations and examples, please watch the accompanying YouTube video. diff --git a/Rollback/README.md b/Rollback/README.md new file mode 100644 index 0000000..d6cb538 --- /dev/null +++ b/Rollback/README.md @@ -0,0 +1,84 @@ +# Rollback a Kubernetes Deployment +This readme file provides step-by-step instructions on how to deploy and manage the Nginx web server using Kubernetes Deployment. It also covers the process of rolling back to previous revisions if necessary. + +## Deployment Creation +To deploy the Nginx web server, follow these steps: + +- Create a file named nginx-deployment.yaml: +``` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + run: nginx +spec: + replicas: 3 + selector: + matchLabels: + run: nginx + template: + metadata: + labels: + run: nginx + spec: + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 80 +``` + +- Run the following command to deploy the Nginx server using the nginx-deployment.yaml file: +``` +kubectl apply -f nginx-deployment.yaml --record=true +``` + +## Checking Deployment Status +To verify the deployment status, execute the following command: +``` +kubectl get deployment +``` + +The output will display information about the deployed Nginx server, including the number of replicas. + +## Upgrading the Deployment Image +If you need to upgrade the Nginx image in the deployment, follow these steps: + +- Run the following command to update the image to nginx:1.16.1: +``` +kubectl set image deployment/nginx-deployment nginx=nginx:1.16.1 --record=true +``` + +- To check the rollout status, use the following command: +``` +kubectl rollout status deployment/nginx-deployment +``` + +## Rolling Back a Deployment +In case an upgrade causes issues and you need to roll back to a previous version, follow these steps: + +- Use the command below to view the revision history of the deployment: +``` +kubectl rollout history deployment/nginx-deployment +``` + +- To see the details of a specific revision (e.g., revision 2), run the following command: +``` +kubectl rollout history deployment/nginx-deployment --revision=2 +``` + +- To perform a general rollback to the previous revision, execute the command: +``` +kubectl rollout undo deployment/nginx-deployment +``` + +- If you want to rollback directly to a specific revision number (e.g., revision 1), use the following command: +``` +kubectl rollout undo deployment/nginx-deployment --to-revision=1 +``` + +- To verify the rollback, you can describe the deployment using the command: +``` +kubectl describe deployment nginx-deployment +``` diff --git a/Service/README.md b/Service/README.md new file mode 100644 index 0000000..6449b4f --- /dev/null +++ b/Service/README.md @@ -0,0 +1,63 @@ +# Kubernetes Service Creation + +## Introduction +This README provides step-by-step instructions on how to create and manage Kubernetes services. The instructions cover four specific questions related to creating and deleting services for pods. This guide accompanies a YouTube video tutorial demonstrating the practical implementation of these questions. + +Video Tutorial: [Link to YouTube Video](https://youtu.be/YZ-jXnNw0sk) + +### Question 1: Create two pods named "blue" and "red" using nginx image. The "blue" pod should be exposed on port 80. + +To create execute the following commands: +``` +kubectl run blue --image=nginx --port=80 +kubectl run red --image=nginx +``` + +### Question 2: Create a nodeport service to expose the "blue" pod. The service should allow external access to the pod on the same port (port 80). + +To create execute the following command: +``` +kubectl expose pod blue --type=NodePort --port=80 +``` + +### Question 3: Create a clusterip service to expose the "red" pod. This service allows internal access within the Kubernetes cluster. + +To create execute the following command: +``` +kubectl expose pod red --type=ClusterIP --port=80 +``` + +### Question 4: Delete the nodeport service that was created for the "blue" pod. + +To delete execute the following command: +``` +kubectl delete service blue +``` + +### Question 5: Recreate a nodeport service for the "blue" pod, this time using the following custom port settings: +#### Port: 8080 +#### NodePort: 32711 +#### TargetPort: 80 + +To recreate execute the following command: +- Create a file named blue-service.yaml. +``` +apiVersion: v1 +kind: Service +metadata: + name: blue-service +spec: + selector: + app: blue + type: NodePort + ports: + - port: 8080 + targetPort: 80 + nodePort: 32711 +``` +- Apply the configuration using below command: +``` +kubectl apply -f blue-service.yaml +``` + +This will create the NodePort service for the "blue" pod with the specified custom port settings. diff --git a/Static Pods/README.md b/Static Pods/README.md new file mode 100644 index 0000000..209ec91 --- /dev/null +++ b/Static Pods/README.md @@ -0,0 +1,46 @@ +# StaticPods in Kubernetes +This README provides instructions on creating and managing static pods in Kubernetes. + +### Create a Static Pod with the Name "static-web" Using the Nginx Image. +To create a static pod with the name "static-web" using the Nginx image, follow these steps: + +- Create a YAML file named static-web.yaml with the following contents: +``` +apiVersion: v1 +kind: Pod +metadata: + name: static-web +spec: + containers: + - name: nginx + image: nginx +``` + +- Apply the pod definition using the command: +``` +kubectl apply -f static-web.yaml +``` + +- Verify the successful creation of the static pod using the command: +``` +kubectl get pods +``` + +### Copy the pod YAML to the folder designated for static pod's YAML files +To copy the pod YAML to the folder designated for static pod's YAML files, complete the following steps: + +- Locate the folder on the Kubernetes node that contains the static pod's YAML files, typically /etc/kubernetes/manifests/. +- Copy the static-web.yaml file into the folder using the command: +``` +sudo cp static-web.yaml /etc/kubernetes/manifests/ +``` + +### 3. How to Ensure that the Pod is Started by Kubelet? +To ensure that the pod is started by kubelet, follow these steps: + +- Monitor the pod's status using the command: +``` +kubectl get pods +``` + +Confirm that the pod's status changes to "Running," indicating that kubelet has successfully started the static pod. diff --git a/Taints and Tolerations/README.md b/Taints and Tolerations/README.md new file mode 100644 index 0000000..0245407 --- /dev/null +++ b/Taints and Tolerations/README.md @@ -0,0 +1,43 @@ +# Taints and Tolerations in Kubernetes +This repository contains practical questions and solutions related to taints and tolerations in Kubernetes. The questions are based on the video tutorial [Link to video](https://youtu.be/y4UarwGKZQQ). + +## Question 1: Taint a node with the Noschedule taint effect and set the key-value pair to run: mypod. +Solution: Use the following command to apply the taint to the desired node: +``` +kubectl taint nodes run=mypod:NoSchedule +``` + +## Question 2: Create a pod named "test" and check the node on which it is scheduled. +Solution: Use the following command to create the pod and view its scheduled node: +``` +kubectl create pod test +kubectl get pod test -o wide +``` + +## Question 3: Create a pod and add a toleration to it with the following specifications: +### Key: key1 +### Operator: Equal +### Value: value1 +### Effect: Noschedule +Solution: Use the following YAML definition to create the pod with the toleration: +``` +apiVersion: v1 +kind: Pod +metadata: + name: mypod +spec: + containers: + - name: mycontainer + image: nginx +tolerations: +- key: key1 + operator: Equal + value: value1 + effect: NoSchedule +``` + +### Question 4: Remove the taint effect from the node that was previously tainted. +Solution: Use the following command to remove the taint from the node: +``` +kubectl taint nodes run=mypod:NoSchedule- +```