0% found this document useful (0 votes)
51 views42 pages

Kubernetes Commands

This document provides commands and explanations for working with Kubernetes. It covers getting cluster info, creating and interacting with pods, replication controllers, deployments, jobs, secrets, persistent volumes and more.

Uploaded by

MANAPADU SURESH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views42 pages

Kubernetes Commands

This document provides commands and explanations for working with Kubernetes. It covers getting cluster info, creating and interacting with pods, replication controllers, deployments, jobs, secrets, persistent volumes and more.

Uploaded by

MANAPADU SURESH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Kubernetes commands

Kubernetes running on 443 port


# kubectl cluster-info - to know about cluster
#docker --version -- to know thw docker vertion in kubernetes
# kubectl create -f filename.yml -- to run file
# kubeadm token create --print-join-command -- to generate token

# kubectl get pods --- to list pods


# kubectl get pods podname -- to see specific pod status
# kubectl get pods -o wide --- to list pods in details
# kubectl get pods podname -o yaml --it will display pod config filr in yml format
# kubectl get pod podname -o json --it will display pod config filr in json format
# kubectl describe pod podname -- it will show all the details of pod

# kubectl describe rs rsname

# kubectl describe deploy deploymentname

# kubectl describe rc replication controller name -- it will show all the details of replicatin controller

# kubectl exec -it podname -- /bin/bash -- to enter into pod(it =intractive it vunnapude /bin/bash
vuntundhi ante pod bash shell tho intract avuthundhi)

# kubectl delete pod podname – to delete pod

# kubectl exec <pod name> date --to print date from running container without interring into pod

# kubectl exec <pod name> -c <container name> date ---if we have more than one container we can
mention container name

# kubectl exec -it <pod name> /bin/bash --to enter into container

# kubectl logs <pod name> ---to see logs of container

# kubectl logs -f<pod name> --to see logs from running container
Pod manifest file

Metadata name =name of object(pod,deployment,rc,rs,service), container name =container name

Name and app = is our choise ,we can give any name

1st stable version of kuberneties -v1


# Kubectl get pod -l app=labelname -- it will display specific pods based on label

# Kubectl scale rc rcname --replicas=5 ---to increase pods

# kebectl scale deployment deployment name --replicas=5

# Kubectl delete -f rcname.yml -- it will delete

# Kubectl get rc -- it will list all replication controller

# Kubectl delete -f filename.yml -- it wii delete all the objects which are part of this manifest file
including pods and rc

# Kubectl delete rc rcname --- it wii delete all the objects which are part of this manifest file including
pods and rc

Replicaset manifest file


# Kubectl set image deploy deployname containername=image name:vertion -- roll update(to
change version)

Ex: kubectl set image deploy nginx-deployment nginx-container=nginx:1.9.1

# Kubectl edit deploy deploymentname --- it is also to change version (after enter this command
deployment file will be open then just change version number then save and exit then it will get
automatically updated)

# Kubectl rollout status deployment/deployment name --- to check roll out successfully done or not

# kubectl set image deploy deployment name container name:version --record -- when we minction
record ,it will record all logs

ex: kubectl set image deploy nginx-deployment nginx-container:1.7.9 --record

# kubectl rollout history deployment/deployment name -- to know what commands we exiquted


erliar

# kubectl rollout undo deployment/deployment name --to roll back to older version
Job
Secrets
We can create secrets in two ways 1 .kubectl 2.manifest file
Syntax to creating secrets by using kubectl command
Manifest file for creating secrets
we can mount secrets into the pod in two ways

Using volume
Using environmental variable

PV and PVC
pdname = persistence disk name
fstype = file system type

We need to create persistent disk storage on google cloud before mention it in pv manifest
file (gcePerssistentdisk:)
(pdName: my-data-disk)

( filetype: ext4)
If we are not created it getting error like this
 awsElasticBlockStore ----in aws
Dynamic pv
We can create multiple pvc s on same storageclass
Daemonset
What is the difference between kubectl create and kubectl apply

Kubectl create is a imperative and kubectl apply is declarative

kubectl create can only be used if there are no existing resources and if you
want to create new resources.
If the resource is already created and running, create will raise an error, To avoid
that, use the kubectl get command to check if there is already an existing
resource; then use kubectl apply to update to the latest configuration.

HELM
What is helm chart ?

Helm chart is package manager for our Kubernetes cluster and it contains all the resource yaml files
of application , it responsible for upgrading , installation and uninstallation of software packages

Template structure contains chart.yml, template, value.yml files

Helm create helm chart name  to create helm chart

Ex: # helm create helloworld

# helm delete release name  to delete helm chart

# helm list -a  to list all helm charts which install by you

# Tree helloworld

helloworld

├── charts

├── Chart.yaml

├── templates

│ ├── deployment.yaml

│ ├── _helpers.tpl

│ ├── hpa.yaml

│ ├── ingress.yaml

│ ├── NOTES.txt

│ ├── serviceaccount.yaml

│ ├── service.yaml

│ └── tests

│ └── test-connection.yaml

└── values.yaml

# helm template helm chart name  it will show template which consist all resource of k8s

# helm lint helm chart name  it will show all chat errors that we done in helm chart
# helm install <FIRST_RELEASE_NAME> <CHART_NAME>
Ex: #helm install myhelloworld helloworld  to install helm chart

# helm list -a  to list all helm charts you installed

#helm repo add <REPOSITORY_NAME> <REPOSITORY_URL>  to add helm chart repository


ex: helm repo add bitnami https://charts.bitnami.com/bitnami

# helm repo list  to listing the repositories we have added so far.

# Helm repo update  To update repository

# Helm repo index helloworld  to create index.yaml inside our packaged charts directory

# helm repo remove reponame  to remove helm chart repository

# helm plugin install https://github.com/databus23/helm-diff  to install plugin

# helm plugin list  to list all plugins

# helm plugin uninstall plugin name  to remove plugin

1. helm install --dry-run --debug helm chart name :- It will validate


and verify your chart by connecting to kubernetes api server and after
successful validation it will render the manifest in the form of
YAMLs(kubernetes resources)
helm template and helm install –dry-run --debug  both commands are helps to debugging and
troubleshooting the helm charts

# helm upgrade <release name> <helm chart name>  to update helm chart

# helm rollback <release name> <revision number> we can rollback to any revision

Ex: # helm rollback myrelease 1

Note: release name not contain upper characters(capital latters), space and special characters

# Helmfile sync  to run helm file

# Helm install –set replicacount=2 <release name> <helm chart nmae>  to increase replicacount
without opening value.yaml file

Namespace

Name space helps you to isolating group of k8s resources with in single cluster. names of resources
need to be unique within a single namespace ,but not across the namespace

# kubectl get ns/namespace  to list all namespace

# Kubectl create namespace <namespace name>  to create namespace

# kubectl get pods -n <namespace name>  to list all pods under the specific namespace
# Kubectl get all --all-namespaces  it list all resources of namepaces

# kubectl get all -n namespacename  it will list all resources of specific namepacs
# kubectl config set-context --current --namespace

What is ingress

Kubernetes ingress is not a service but a collection of routing rules that govern how the
external users access services running on the Kubernetes cluster. Ingress sits in front of
the cluster and acts as a smart router. This is always implemented using a third party
called a proxy. Traffic routing is done by an ingress controller.

Secrets
After creating screts we need to mount it into pod
Volume
Environmental variable

Config maps
Syntax of config map
We can create config map in 3 ways

1 dir 2.files 3.literals

1.dir
Creating config map using map
We can mount config map into pod in two ways 1 .volumes 2.environments
literal

environment

You might also like