Skip to content

Latest commit

 

History

History
102 lines (76 loc) · 1.48 KB

kubernetes.md

File metadata and controls

102 lines (76 loc) · 1.48 KB

Random kubernetes commands I forgety

Interacting with clusters

Get cluster information:

kubectl cluster-info

Interacting with running pods

Attempt to exec command against running pod:

kubectl exec -v=10  -n namespace pod_name -- "ls /"

Print logs for running pod:

kubectl logs pod_name    

Getting resources

Get all services in a namespace:

kubectl get -n namespace services

Get all deployments in a namespace:

kubectl get -n namespace deployments

Get all pods in a namespace:

kubectl get -n namespace pods

Get yaml for pod in a namespace:

kubectl get -n namespace pod pod_name -o yaml

Deleting resources

Delete a pod now

kubectl delete -n namespace pod  pod_name --now

Force delete a pod

kubectl delete -n namespace pod  pod_name --grace-period=0 --force

Creating resouces

Create resource defined in yaml:

kubectl apply -f kube.yaml

Validation

To validate a yaml file:

kubectl apply --validate=true --dry-run=client --filename=filename.yaml

Port Forwarding

To port forward to a pod:

kubectl port-forward pod_name 8080:8080

or

kubectl port-forward pods/pod_name 8080:8080

To port forward to a deployment:

kubectl port-forward deployment_name 8080:8080

or

kubectl port-forward deployment/deployment_name 8080:8080

To port forward to a service:

kubectl port-forward svc_name 8080:8080

or

kubectl port-forward svc/svc_name 8080:8080