kubectl

kubectl command is used to manage Kubernetes Clusters.

To install kubectl on Linux, run

wget https://raw.githubusercontent.com/serverok/server-setup/master/install/kubectl.sh
bash kubectl.sh

On Ubuntu, you can install from snap using

sudo snap install kubectl --classic

or with apt

apt-get install kubectl

To get help, run

kubectl help

Check if Kubernetes environment is ready

kubectl version

Run nginx container

kubectl run nginx --image=nginx:1.10.0

Connect to a pod

kubectl exec monolith --stdin --tty -c monolith /bin/sh

Execute a command in pod

kubectl exec POD-ID-HERE -- COMMAND_HERE

Change image used by a pod

kubectl set image deployement/nginx nginx=1.13

Scale a deployment

kubectl scale deployement nginx --replicas=10

Expose a port

kubectl expose deployment nginx --port 80 --type LoadBalancer

Port forward

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

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *