Remove Old Kubernetes Commands File
This commit is contained in:
@@ -1,194 +0,0 @@
|
|||||||
# Kubernetes
|
|
||||||
|
|
||||||
## `kubectl` Command Reference
|
|
||||||
|
|
||||||
### Get State of API Resources
|
|
||||||
```bash
|
|
||||||
kubectl api-resources
|
|
||||||
```
|
|
||||||
|
|
||||||
### Node Management
|
|
||||||
- **Show all nodes:**
|
|
||||||
```bash
|
|
||||||
kubectl get node
|
|
||||||
```
|
|
||||||
|
|
||||||
### Namespace Management
|
|
||||||
- **List all namespaces:**
|
|
||||||
```bash
|
|
||||||
kubectl get namespaces
|
|
||||||
```
|
|
||||||
```bash
|
|
||||||
kubectl get ns
|
|
||||||
```
|
|
||||||
- **Create a custom namespace:**
|
|
||||||
```bash
|
|
||||||
kubectl create ns <namespace-name>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Pod Management
|
|
||||||
- **Get the list of pods in the default namespace:**
|
|
||||||
```bash
|
|
||||||
kubectl get pod
|
|
||||||
```
|
|
||||||
- **Get the list of pods in the default namespace with full information:**
|
|
||||||
```bash
|
|
||||||
kubectl get pod -o wide
|
|
||||||
```
|
|
||||||
- **Get the list of pods in a custom namespace with full information:**
|
|
||||||
```bash
|
|
||||||
kubectl get pod -o wide -n <name-space>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Running a Pod
|
|
||||||
- **Run a new pod:**
|
|
||||||
```bash
|
|
||||||
kubectl run <pod-name> <switch> {
|
|
||||||
--image=<image-name>, # Specifies the container image to use
|
|
||||||
--port=<portnumber>, # Specifies the port that the container exposes
|
|
||||||
-n <namespace-name>, # Specifies the namespace
|
|
||||||
--env="KEY=VALUE", # Sets environment variables in the container
|
|
||||||
--command, # Treats the rest of the arguments as the command to run in the container
|
|
||||||
--replicas=<number>, # Specifies the number of replicas for the deployment
|
|
||||||
--labels="key=value,key2=value2", # Adds labels to the pod(s)
|
|
||||||
--dry-run=client, # Prints the object that would be sent, without creating it
|
|
||||||
--restart=<Always|OnFailure|Never>, # Determines the restart policy for the pod
|
|
||||||
--overrides='<json>', # Provides a JSON override for the generated object
|
|
||||||
--image-pull-policy=<policy>, # Specifies the image pull policy (Always, IfNotPresent, Never)
|
|
||||||
--limits=cpu=<cpu>,memory=<memory>, # Specifies resource limits for the container
|
|
||||||
--requests=cpu=<cpu>,memory=<memory> # Specifies resource requests for the container
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- *Example:*
|
|
||||||
```bash
|
|
||||||
kubectl run mypod --image=nginx --port=80 -n mynamespace \
|
|
||||||
--env="ENV_VAR_NAME=VALUE" --command -- nginx -g "daemon off;" \
|
|
||||||
--replicas=3 --labels="app=myapp,env=prod" --dry-run=client \
|
|
||||||
--restart=Always --overrides='{"spec": {"containers": [{"name": "nginx", "image": "nginx"}]}}' \
|
|
||||||
--image-pull-policy=IfNotPresent --limits=cpu=100m,memory=256Mi \
|
|
||||||
--requests=cpu=50m,memory=128Mi
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
### Deleting a Pod
|
|
||||||
- **Delete a pod in a custom namespace:**
|
|
||||||
```bash
|
|
||||||
kubectl delete pod -n <namespace-name> <pod-name>
|
|
||||||
```
|
|
||||||
|
|
||||||
### API Resource Documentation
|
|
||||||
- **Get documentation of an API resource:**
|
|
||||||
```bash
|
|
||||||
kubectl explain <api-resource-name>
|
|
||||||
```
|
|
||||||
- *Example:*
|
|
||||||
```bash
|
|
||||||
kubectl explain pod
|
|
||||||
```
|
|
||||||
|
|
||||||
### Logging and Pod Information
|
|
||||||
- **Get and follow logs of a pod (pod must be created and running):**
|
|
||||||
```bash
|
|
||||||
kubectl logs -f -n <namespace-name> <podname>
|
|
||||||
```
|
|
||||||
- **Get logs and state information of a pod (works at any time):**
|
|
||||||
```bash
|
|
||||||
kubectl describe pod -n <namespace-name> <podname>
|
|
||||||
```
|
|
||||||
|
|
||||||
### Apply Yaml File
|
|
||||||
```bash
|
|
||||||
kubectl apply -f <yaml-file> -n <namespace-name>
|
|
||||||
```
|
|
||||||
### View Pod Details
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl get pod -n my-ns <pod-name> -o yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
This command retrieves and displays the YAML configuration of the pod `testpod1` in the namespace `my-ns`.
|
|
||||||
|
|
||||||
### Label a Node
|
|
||||||
|
|
||||||
```bash
|
|
||||||
kubectl label node <node-name> kubernetes.io/<var-name>=<var-value>
|
|
||||||
kubectl get nodes --show-labels
|
|
||||||
```
|
|
||||||
### Retrieve the ReplicaSet
|
|
||||||
To retrieve information about the ReplicaSet in the `my-ns` namespace, use the following command:
|
|
||||||
```bash
|
|
||||||
kubectl get rs -n my-ns
|
|
||||||
```
|
|
||||||
|
|
||||||
### Delete All Pods in the Namespace
|
|
||||||
To delete all pods in the `my-ns` namespace, use the following command:
|
|
||||||
```bash
|
|
||||||
kubectl delete pod --all -n my-ns
|
|
||||||
```
|
|
||||||
|
|
||||||
### Change the Replica Count to 5
|
|
||||||
To scale the ReplicaSet to 5 replicas, you can use one of the following methods:
|
|
||||||
|
|
||||||
1. **Using the `kubectl scale` Command**
|
|
||||||
```bash
|
|
||||||
kubectl scale rs my-app --replicas=5 -n my-ns
|
|
||||||
```
|
|
||||||
|
|
||||||
## Commands to Manage the Deployment
|
|
||||||
|
|
||||||
### Scale the Deployment
|
|
||||||
To scale the Deployment to 6 replicas:
|
|
||||||
```bash
|
|
||||||
kubectl -n my-ns scale deployment myapp --replicas 6
|
|
||||||
```
|
|
||||||
|
|
||||||
### Retrieve Deployment, ReplicaSets, and Pods
|
|
||||||
To retrieve information about the Deployment, ReplicaSets, and Pods:
|
|
||||||
```bash
|
|
||||||
kubectl get deployment,rs,po myapp -n my-ns
|
|
||||||
```
|
|
||||||
|
|
||||||
### Delete the Deployment
|
|
||||||
To delete the Deployment:
|
|
||||||
```bash
|
|
||||||
kubectl delete deployment myapp -n my-ns
|
|
||||||
```
|
|
||||||
|
|
||||||
### Retrieve ReplicaSets
|
|
||||||
To retrieve ReplicaSets:
|
|
||||||
```bash
|
|
||||||
kubectl get rs -n my-ns
|
|
||||||
```
|
|
||||||
|
|
||||||
### Rollback a Deployment
|
|
||||||
To undo the last rollout:
|
|
||||||
```bash
|
|
||||||
kubectl rollout undo deployment -n my-ns myapp
|
|
||||||
```
|
|
||||||
|
|
||||||
To view rollout history:
|
|
||||||
```bash
|
|
||||||
kubectl rollout history deployment -n my-ns
|
|
||||||
```
|
|
||||||
|
|
||||||
To view a specific revision:
|
|
||||||
```bash
|
|
||||||
kubectl rollout history deployment -n my-ns --revision 2
|
|
||||||
```
|
|
||||||
|
|
||||||
To rollback to a specific revision:
|
|
||||||
```bash
|
|
||||||
kubectl rollout undo deployment -n my-ns myapp --to-revision 2
|
|
||||||
```
|
|
||||||
|
|
||||||
### Annotate Deployment with Change Cause
|
|
||||||
To add a change cause annotation:
|
|
||||||
```bash
|
|
||||||
kubectl annotate deployment/myapp -n my-ns myapp "kubectl.kubernetes.io/change-cause=v14 released"
|
|
||||||
```
|
|
||||||
|
|
||||||
### Horizontal Pod Autoscaler
|
|
||||||
To create an autoscaler for the Deployment:
|
|
||||||
```bash
|
|
||||||
kubectl -n my-ns autoscale deployment nginx --cpu-percent=50 --min=4 --max=10
|
|
||||||
```
|
|
||||||
Reference in New Issue
Block a user