kubectl, the kubernetes CLI¶
pods¶
Create pods¶
There are 3 differnet ways to create pods from kubectl CLI
-
kubectl run
(run single pod per command) -
kubectl create
(create resources via CLI or YAML) -
kubectl apply
(create/update resources via YAML)
Create ngnix web-server pod
List Pods¶
This will show pods only in the default namespace
List pods with custom namespace
List pods with IP address
List pods& refresh continously
Cluster info
Describe pods¶
Delete pods¶
SSH into a pod¶
Nodes¶
Get Nodes
Namespaces¶
In Kubernetes, namespaces provides a mechanism for isolating groups of resources within a single cluster.
Kubernetes starts with four initial namespaces:
-
default
The default namespace for objects with no other namespace -
kube-system
The namespace for objects created by the Kubernetes system -
kube-public
This namespace is created automatically and is readable by all users (including those not authenticated). This namespace is mostly reserved for cluster usage, in case that some resources should be visible and readable publicly throughout the whole cluster. The public aspect of this namespace is only a convention, not a requirement. -
kube-node-lease
This namespace holds Lease objects associated with each node. Node leases allow the kubelet to send heartbeats so that the control plane can detect node failure.
List all namespaces in cluster
Start a pod with namespace
Deployments¶
Deployment managed by the Kubernetes Deployment controller
tells Kubernetes how to create or modify instances of the pods that hold a containerized application. A Deployment runs multiple replicas of your application and automatically replaces any instances that fail or become unresponsive.
Create/scale deployment¶
Get deployment details¶
Scale deployment¶
Update deployment with new image¶
Check rollout status¶
Remove deployment¶
Rollout¶
Get rollout status
Get rollout history/revision
Undo rollout deployment
Deployment strategies¶
Recreate¶
This strategy will terminate all the old pods and then create new ones with the new configuration. This will cause downtime.
Rolling Update¶
This strategy will create new pods with the new configuration and then terminate the old ones gradually. It will create new pods with the new configuration and then terminate the old ones gradually. This will not cause downtime. This is the default strategy.
Services¶
Create a ClusterIP¶
Expose a internal port 80 to the external port 8080
Warning
ClusterIP service will allow connecting from inside the kubernetes cluster. Used when we want to block connections from outside the kubernetes cluster but want the cluster itself to have access.
Create a NodePort¶
Info
NodePort service will allow connecting from outside the kubernetes cluster
Create a LoadBalancer¶
Info
NodePort service will allow connecting from outside the kubernetes cluster
List services¶
Get Service DetailsDelete service
Get all objects in the default namespace
Cleanup¶
Delete all resources the default namespace
Tip
This also deletes the default kubernetes(ClusterIP) service but it is re-created automatically
Replicas¶
Replication Controller¶
Get Replication Controller
Replica Set¶
Get Replica Set
Scale Replica Set
Warning
This will create 5 replicas of the pods defined in the replicaset.yml file but does not update the replicaset.yml file
Edit Replica Set Inline
Info
This will open the replicaset.yml file in the default editor and any changes made will be applied immediately to the replicaset
YAML Configuration¶
Every kubernetes configuration file has 3 parts
-
metadata Eg:
name
&labels
-
specification Eg:
spec
-
status, automatically generated by kubernetes