Skip to content

Instantly share code, notes, and snippets.

@pjmazenot
Last active December 27, 2017 22:11
Show Gist options
  • Save pjmazenot/b89da2be1c27748d6464a75f63a0d772 to your computer and use it in GitHub Desktop.
Save pjmazenot/b89da2be1c27748d6464a75f63a0d772 to your computer and use it in GitHub Desktop.
Useful commands for k8s management
# Get pods list in all namespaces
# The `--all-namespaces` can be added to most of the kubectl retrieving commands
kubectl get pods --all-namespaces
# Restart a pod with the definition file
# E.g: `kubectl delete pods mysql-default-934tl && kubectl create -f ./mysql-default.yaml`
# Errors:
# - Pod not found: add `-n NAMESPACE` after the delete command
kubectl delete pods [POD] && kubectl create -f [YAML_POD_DEFINTION_FILE]
# If the creation does not work because the pod respawn immediately you can use the following
# commands to identify what makes the pod respawn
kubectl get deployment --all-namespaces
kubectl get jobs --all-namespaces
kubectl get replicationcontroller --all-namespaces
# Then you can delete it and recreate the new pod
kubectl delete deployment [POD] -n [NAMESPACE]
kubectl delete replicationcontroller [POD] -n [NAMESPACE]
# You can also replace a deployment, rc, service with
# If you get the error "Immutable field" you have to delete it and recreate it
kubectl replace -f [YAML_DEPLOYMENT_DEFINTION_FILE] -n [NAMESPACE]
# Restart a pod without the definition file
# E.g: `kubectl get pod nginx-ingress-controller-bwplm -n kube-system -o yaml | kubectl replace --force -f -`
kubectl get pod [POD] -n [NAMESPACE] -o yaml | kubectl replace --force -f -
# Test if a port is open
# E.g: `nc -zv 192.168.99.100 80 443 3306`
nc -zv [HOST] [PORT1 (...PORTn)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment