Kubernetes Objects
| Create Pod | kubectl run nginx --generator=run-pod/v1 --image=nginx |
| Create in particular namespace | kubectl run nginx --generator=run-pod/v1 --image=nginx -n NAMEPSPACE |
| Dry run,print object without creating it | kubectl run POD_NAME --generator=run-pod/v1 --image=nginx --dry-run -o yaml |
| Create and write its spec to file | kubectl run POD_NAME --image=nginx --restart=Never --dry-run -o yaml > pod.yaml |
| Create from File | kubectl create -f pod.yaml |
| Create from File in particular namespace | kubectl create -f pod.yaml -n NAMEPSPACE |
| List Pods | kubectl get po or kubectl get pod or kubectl get pods |
| List pods in all namespaces | kubectl get pods --all-namespaces or kubectl get pods -A |
| List/Get Particular Pod | kubectl get po #POD_NAME# or kubectl get pod #POD_NAME# or kubectl get pods #POD_NAME# |
| List pods with more information | kubectl get pods -owide |
| List pod in Json output format | kubectl get pods -o json |
| List pod in YAML output format | kubectl get pods -o yaml |
| List pods with more information in custom columns | kubectl get pod POD_NAME -o custom columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image |
| Delete Pods | kubectl delete pod #POD_NAME# or kubectl delete -f pod.yaml or kubectl delete pod/#POD_NAME# |
| Delete pod in particular namespace | kubectl delete pod #POD_NAME# -n #NAMEPSPACE_NAME# |
| Delete pod forcefully | kubectl delete pod #POD_NAME# --grace-period=0 --force |
| Check Pod Logs | kubectl logs #POD_NAME# |
| Check Pod Logs (multi-container case) | kubectl logs #POD_NAME# -c #CONTAINER_NAME# |
| Tail Pod Logs | kubectl logs -f #POD_NAME# |
| Tail Pod Logs (multi-container case) | kubectl logs -f #POD_NAME# -c #CONTAINER_NAME# |
| Verbose Debug information/describe pod | kubectl describe pod #POD_NAME# |
| Watch pod | kubectl get pod POD_NAME --watch |
| Verbose Debug information/describe pod | kubectl patch pod #POD_NAME# -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname"}]}}' |
| Exec to pod | kubectl exec -it #POD_NAME# bash |
| Run command in existing pod | kubectl exec -it #POD_NAME# -- ls / |
| Run command in existing pod (multi-container case) | kubectl exec -it #POD_NAME# -c #CONTAINER_NAME# -- ls / |
| Create deployment | kubectl create deployment #DEPLOYMENT_NAME# --image=busybox |
| Create deployment in particular namespace | kubectl create deployment #DEPLOYMENT_NAME# --image=busybox -n NAMEPSPACE |
| Run deployment with 2 Replicas | kubectl run #DEPLOYMENT_NAME# --image=nginx --replicas=2 --port=80 |
| Run deployment and expose it | kubectl run #DEPLOYMENT_NAME# --image=nginx --port=80 --expose |
| Create deployment from File | kubectl create -f deployment.yaml |
| Create deployment from File in particular namespace | kubectl create -f deployment.yaml -n #NAMEPSPACE_NAME# |
| List deployments | kubectl get deploy or kubectl get deployment or kubectl get deployments |
| List deployments in all namespaces | kubectl get deploy --all-namespaces or kubectl get deploy -A |
| List deployments in particular namespace | kubectl get deploy -n #NAMESPACE_NAME# |
| List/Get Particular deployment | kubectl get deploy #DEPLOY_NAME# or kubectl get deployment #DEPLOY_NAME# or kubectl get deployments #DEPLOY_NAME# |
| List deployments with more information | kubectl get deployment -owide |
| Delete deployment | kubectl delete deploy #DEPLOYMENT_NAME# or kubectl delete -f deployment.yaml or kubectl delete deploy/#DEPLOYMENT_NAME# |
| Delete deployment in particular namespace | kubectl delete deployment #DEPLOYMENT_NAME# -n #NAMEPSPACE_NAME# |
| Verbose Debug information/describe particular Deployment | kubectl describe deployment #DEPLOYMENT_NAME# |
| Decribe All Deployments | kubectl describe deployments |
| Watch Deployment | kubectl get deployment #DEPLOYMENT_NAME# --watch |
| Edit Deployment | kubectl edit deployment #DEPLOY_NAME# |
| Patch/Update Deployment (Update nginx pod image to 1.9.1 instead of 1.7.9) | kubectl set image deployment/nginx-deployment ngnix=nginx:1.9.1 --record |
| Scaliing Deployment | kubectl scale deployment/nginx-deployment --replicas=2 |
| Deployment Rollout Status | kubectl rollout status deployment/#DEPLOYMENT_MAME# |
| Deployment Rollout History | kubectl rollout history deployment/#DEPLOYMENT_MAME# |
| Pausing Rollout Deployment | kubectl rollout pause deployment/#DEPLOYMENT_MAME# |
| Resuming Rollout Deployment | kubectl rollout resume deployment/#DEPLOYMENT_MAME# |
| Rollback Deployment to Previous Verion | kubectl rollout undo deployment/#DEPLOYMENT_MAME# |
| Create ReplicaSet | kubectl create -f replicaset.yaml |
| List ReplicaSets | kubectl get rs or kubectl get replicaset or kubectl get replicasets |
| List ReplicaSets in all namespaces | kubectl get rs --all-namespaces or kubectl get rs -A |
| List ReplicaSet with more information | kubectl get rs -owide |
| List Specific ReplicaSet | kubectl get rs #REPLICASET_NAME# |
| Delete ReplicaSet | kubectl delete rs #REPLICASET_NAME# or kubectl delete -f replicaset.yaml |
| Create ClusterIP Service | kubectl create service clusterip #SERVICE_NAME# --tcp=5678:8080 |
| Create ClusterIP Service in Headless Mode | kubectl create service clusterip #SERVICE_NAME# --clusterip="None" |
| Create NodePort Service | kubectl create service nodeport #SERVICE_NAME# --tcp=5678:8080 |
| Create LoadBalancer Service | kubectl create service loadbalancer #SERVICE_NAME# --tcp=5678:8080 |
| Create ExternalName Service | kubectl create service externalname #SERVICE_NAME# --extername example.com |
| List Service | kubectl get svc or kubectl get service or kubectl get services |
| List Specific Service | kubectl get svc #SERVICE_NAME# |
| Delete Service | kubectl delete svc #SERVICE_NAME# or kubectl delete -f service.yaml |
| Verbose Debug information/Describe Service | kubectl describe svc #SERVICE_NAME# |
| Create Namespace | kubectl create ns #NAMESPACE_NAME# or kubectl create -f namespace.yaml |
| List Namespace | kubectl get ns or kubectl get namespace or kubectl get namespaces |
| List Specific Namespace | kubectl get ns #NAMESPACE_NAME# |
| Delete Namespace | kubectl delete ns #NAMESPACE_NAME# or kubectl delete -f namespace.yaml |
| Verbose Debug information/Describe Namespace | kubectl describe ns #NAMESPACE_NAME# |
| Create ServiceAccount | kubectl create sa #SERVICE_ACCOUNT_NAME# or kubectl create -f service-account.yaml |
| List ServiceAccount | kubectl get sa or kubectl get serviceaccount or kubectl get serviceaccounts |
| List Specific ServiceAccount | kubectl get sa #SERVICE_ACCOUNT_NAME# |
| Delete ServiceAccount | kubectl delete sa #SERVICE_ACCOUNT_NAME# or kubectl delete -f service-account.yaml |
| Verbose Debug information/Describe ServiceAccount | kubectl describe sa #SERVICE_ACCOUNT_NAME# |
| List DaemonSets | kubectl get ds or kubectl get daemonset or kubectl get daemonsets |
| List DaemonSets in all namespaces | kubectl get ds --all-namespaces or kubectl get ds -A |
| List DaemonSet with more information | kubectl get ds -owide |
| List Specific DaemonSet | kubectl get ds #DAEMONSET_NAME# |
| Delete DaemonSet | kubectl delete ds #DAEMONSET_NAME# or kubectl delete -f daemonset.yaml |
| Verbose Debug information/Describe DaemonSet | kubectl describe ds #DAEMONSET_NAME# |
| Create Job | kubectl create job #JOB_NAME# --image=busybox |
| Create Job with linux command | kubectl create job #JOB_NAME# --image=busybox --date |
| Create Job from a cronjob named "cronjob-1" | kubectl create job #JOB_NAME# --from=cronjob/cronjob-1 |
| List Jobs | kubectl get job or kubectl get jobs |
| List Jobs in all namespaces | kubectl get job --all-namespaces or kubectl get job -A |
| List Jobs with more information | kubectl get job -owide |
| List Specific Job | kubectl get job #JOB_NAME# |
| Delete job | kubectl delete job #JOB_NAME# or kubectl delete -f job.yaml |
| Verbose Debug information/Describe Job | kubectl describe job #JOB_NAME# |
| Create Scheduled CronJob | kubectl create cronjob #CRONJOB_NAME# --image=busybox --schedule="*/1 * * * *" |
| List CronJobs | kubectl get cj or kubectl get cronjob or kubectl get cronjobs |
| List CronJobs in all namespaces | kubectl get cj --all-namespaces or kubectl get cj -A |
| List CronJobs with more information | kubectl get cj -owide |
| List Specific CronJob | kubectl get cj #CRONJOB_NAME# |
| Delete CronJob | kubectl delete cj #CRONJOB_NAME# or kubectl delete -f cronjob.yaml |
| Verbose Debug information/Describe CronJob | kubectl describe cj #CRONJOB_NAME# |
| Create ConfigMap with from literal | kubectl create configmap #CONFIG_MAP_NAME# --from-literal=key1=config1 --from-literal=key2=config2 |
| Create a new configmap from a file | kubectl create configmap #CONFIG_MAP_NAME# --from-file=path/to/configfile |
| Create ConfigMap with from environment file | kubectl create configmap #CONFIG_MAP_NAME# --from-env-file=path/to/environment-config-file |
| List ConfigMaps | kubectl get cm or kubectl get ConfigMap or kubectl get ConfigMaps |
| List ConfigMaps in all namespaces | kubectl get ConfigMap --all-namespaces or kubectl get ConfigMap -A |
| List ConfigMaps with more information | kubectl get ConfigMap -owide |
| List Specific ConfigMap | kubectl get ConfigMap #CONFIG_MAP_NAME# |
| Delete ConfigMap | kubectl delete ConfigMap #CONFIG_MAP_NAME# or kubectl delete -f configmap.yaml |
| Verbose Debug information/Describe ConfigMap | kubectl describe ConfigMap #CONFIG_MAP_NAME# |
| Create Secret with from literal | kubectl create secret generic #SECRET_NAME# --from-literal=secret_key1=secret_value1 --from-literal=secret_key2=secret_value2 |
| Create a new Secret from a file | kubectl create secret generic #SECRET_NAME# --from-file=secret_key=path/to/secret_value_file |
| List Secrets | kubectl get secret or kubectl get secrets |
| List Secrets in all namespaces | kubectl get secret --all-namespaces or kubectl get secret -A |
| List Secrets with more information | kubectl get secret -owide |
| List Specific Secret | kubectl get secret #SECRET_NAME# |
| Delete Secret | kubectl delete secret #SECRET_NAME# or kubectl delete -f secret.yaml |
| Verbose Debug information/Describe Secret | kubectl describe secret #SECRET_NAME# |
| Create Persistent Volume | kubectl create pv #NAMESPACE_NAME# or kubectl create -f persistent_volume.yaml |
| List Persistent Volume | kubectl get pv or kubectl get persistentvolume or kubectl get persistentvolumes |
| List Specific Persistent Volume | kubectl get pv #PV_NAME# |
| Delete Persistent Volume | kubectl delete pv #PV_NAME# or kubectl delete -f persistent_volume.yaml |
| Verbose Debug information/Describe Persistent Volume | kubectl describe pv #PV_NAME# |
| Create Persistent Volume Claim | kubectl create pvc #NAMESPACE_NAME# or kubectl create -f persistent_volume_claim.yaml |
| List Persistent Volume Claim | kubectl get pvc or kubectl get persistentvolumeclaim or kubectl get persistentvolumeclaims |
| List Specific Persistent Volume Claim | kubectl get pvc #PVC_NAME# |
| Delete Persistent Volume Claim | kubectl delete pvc #PVC_NAME# or kubectl delete -f persistent_volume_claim.yaml |
| Verbose Debug information/Describe Persistent Volume Claim | kubectl describe pvc #PVC_NAME# |
Kubernetes Cluster (Master and Worker) Nodes Required Ports
Master Nodes - Required Ports
| Protocol | Direction | Port Range | Purpose | Used By |
|---|---|---|---|---|
| TCP | Inbound | 6443* | Kubernetes API server | All |
| TCP | Inbound | 2379-2380 | etcd server client API | kube-apiserver, etcd |
| TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
| TCP | Inbound | 10251 | kube-scheduler | Self |
| TCP | Inbound | 10252 | kube-controller-manager | Self |
Worker Nodes - Required Ports
| Protocol | Direction | Port Range | Purpose | Used By |
|---|---|---|---|---|
| TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
| TCP | Inbound | 30000-32767 | NodePort Services† | All |
No comments:
Post a Comment