kubectl
kubectl command is used to manage Kubernetes Clusters.
To install kubectl on Linux, run
1 2 |
wget https://raw.githubusercontent.com/serverok/server-setup/master/install/kubectl.sh bash kubectl.sh |
On Ubuntu, you can install from snap using
1 |
sudo snap install kubectl --classic |
or with apt
1 |
apt-get install kubectl |
To get help, run
1 |
kubectl help |
Check if Kubernetes environment is ready
1 |
kubectl version |
Run nginx container
1 |
kubectl run nginx --image=nginx:1.10.0 |
Connect to a pod
1 |
kubectl exec monolith --stdin --tty -c monolith /bin/sh |
Execute a command in pod
1 |
kubectl exec POD-ID-HERE -- COMMAND_HERE |
Change image used by a pod
1 |
kubectl set image deployement/nginx nginx=1.13 |
Scale a deployment
1 |
kubectl scale deployement nginx --replicas=10 |
Expose a port
1 |
kubectl expose deployment nginx --port 80 --type LoadBalancer |
Port forward
1 |
kubectl port-forward monolith 10080:80 |
Some useful commands
kubectl get no kubectl get nodes |
List all available nodes |
kubectl get po kubectl get pods |
List all available pods |
kubectl get services kubectl get svc |
List all available services |
kubectl get deployments | List all deployments |
kubectl config current-context | Shows with cluster kubectl is connected to. |
kubectl cluster-info | Shows info on current cluster. |
kubectl scale deployment DEPLOYMENT_NAME –replicas 4 | Scale a deployment to 4 replicas. |
kubectl create ns production | Create namespace “production” |
kubectl -n kube-system create sa tiller | Create tiller account for helm |
kubectl delete all –all | delete all resources in cluster |
See Kubernetes