-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4786a74
commit ab9557b
Showing
15 changed files
with
869 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <pod_name> | ||
``` | ||
|
||
## 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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <node-name> 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 <node-name> capacity- | ||
``` |
Oops, something went wrong.