Showing 30 question(s)
Answer:
Kubernetes (K8s) is an open-source container orchestration platform used to automate the deployment, scaling, and management of containerized applications.
Code Example:
# Check Kubernetes version
kubectl version
# Cluster information
kubectl cluster-infoAnswer:
Kubernetes automates application deployment, scaling, load balancing, self-healing, service discovery, rolling updates, and resource management for containerized applications.
Code Example:
kubectl get nodes
kubectl get pods
kubectl get deploymentsAnswer:
A Kubernetes Cluster consists of one or more control plane nodes and multiple worker nodes that run containerized workloads.
Code Example:
kubectl cluster-info
kubectl get nodesAnswer:
The control plane includes API Server, etcd, Scheduler, Controller Manager, and Cloud Controller Manager (optional).
Code Example:
kubectl get componentstatuses
kubectl get nodesAnswer:
A Worker Node is a machine that runs application workloads. It contains kubelet, kube-proxy, and a container runtime such as containerd.
Code Example:
kubectl get nodes -o wideAnswer:
A Pod is the smallest deployable unit in Kubernetes. It can contain one or more containers sharing the same network and storage.
Code Example:
kubectl get pods
kubectl describe pod my-podAnswer:
Yes. Multiple tightly coupled containers can run inside a single Pod and share networking and storage.
Code Example:
apiVersion: v1
kind: Pod
metadata:
name: multi-container-pod
spec:
containers:
- name: app
image: nginx
- name: sidecar
image: busyboxAnswer:
A Pod can be created using a YAML manifest and the kubectl apply command.
Code Example:
kubectl apply -f pod.yaml
kubectl get podsAnswer:
Use the kubectl delete pod command followed by the Pod name.
Code Example:
kubectl delete pod my-podAnswer:
The kubectl logs command displays the logs generated by a Pod.
Code Example:
kubectl logs my-pod
kubectl logs -f my-podAnswer:
A Deployment manages Pods and ReplicaSets. It provides declarative updates, scaling, self-healing, and rolling updates for applications.
Code Example:
kubectl get deployments
kubectl create deployment nginx --image=nginxAnswer:
A ReplicaSet ensures that the specified number of identical Pod replicas are always running.
Code Example:
kubectl get replicasets
kubectl describe replicaset my-rsAnswer:
You can scale a Deployment manually using the kubectl scale command or automatically using the Horizontal Pod Autoscaler.
Code Example:
kubectl scale deployment nginx --replicas=5
kubectl get podsAnswer:
A Rolling Update gradually replaces old Pods with new ones without downtime, ensuring continuous availability.
Code Example:
kubectl set image deployment/nginx nginx=nginx:latest
kubectl rollout status deployment/nginxAnswer:
Kubernetes allows rolling back to a previous Deployment revision if a new deployment fails.
Code Example:
kubectl rollout undo deployment/nginx
kubectl rollout history deployment/nginxAnswer:
A Service provides a stable network endpoint that allows communication with a group of Pods.
Code Example:
kubectl get services
kubectl expose deployment nginx --port=80Answer:
The four main Service types are ClusterIP, NodePort, LoadBalancer, and ExternalName.
Code Example:
kubectl get svcAnswer:
ClusterIP is the default Service type that exposes an application internally within the Kubernetes cluster.
Code Example:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: ClusterIP
selector:
app: nginx
ports:
- port: 80Answer:
A NodePort Service exposes an application on a static port of every worker node, allowing external access.
Code Example:
apiVersion: v1
kind: Service
metadata:
name: nodeport-service
spec:
type: NodePort
selector:
app: nginx
ports:
- port: 80
nodePort: 30080Answer:
A LoadBalancer Service exposes an application externally using a cloud providers load balancer.
Code Example:
apiVersion: v1
kind: Service
metadata:
name: lb-service
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- port: 80Answer:
A Namespace is a logical partition within a Kubernetes cluster that isolates resources between different teams, projects, or environments.
Code Example:
# List namespaces
kubectl get namespaces
# Create a namespace
kubectl create namespace development
# View resources in a namespace
kubectl get pods -n developmentAnswer:
A ConfigMap stores non-sensitive configuration data as key-value pairs. Applications can consume ConfigMaps as environment variables, command-line arguments, or mounted files.
Code Example:
kubectl create configmap app-config --from-literal=ENV=Production
kubectl get configmapsAnswer:
A Secret securely stores sensitive information such as passwords, API keys, certificates, and tokens. Secrets should be used instead of ConfigMaps for confidential data.
Code Example:
kubectl create secret generic db-secret --from-literal=password=MyPassword123
kubectl get secretsAnswer:
Ingress manages external HTTP and HTTPS access to services inside a Kubernetes cluster. It supports routing, SSL termination, and virtual hosting.
Code Example:
kubectl get ingress
kubectl apply -f ingress.yamlAnswer:
A Persistent Volume is a storage resource managed by Kubernetes that exists independently of Pods and can be reused across applications.
Code Example:
kubectl get pv
kubectl describe pv my-pvAnswer:
A Persistent Volume Claim is a request for storage made by a Pod. Kubernetes binds the claim to a matching Persistent Volume.
Code Example:
kubectl get pvc
kubectl describe pvc my-pvcAnswer:
A StatefulSet manages stateful applications that require stable network identities, persistent storage, and ordered deployment or scaling.
Code Example:
kubectl get statefulsets
kubectl apply -f statefulset.yamlAnswer:
A DaemonSet ensures that one Pod runs on every worker node. It is commonly used for logging, monitoring, and networking agents.
Code Example:
kubectl get daemonsets
kubectl apply -f daemonset.yamlAnswer:
A Job creates one or more Pods to execute a task until completion. Jobs are typically used for batch processing and one-time tasks.
Code Example:
kubectl get jobs
kubectl apply -f job.yamlAnswer:
Use namespaces for isolation, define resource requests and limits, implement readiness and liveness probes, use ConfigMaps and Secrets appropriately, avoid running containers as root, enable RBAC, use rolling updates, monitor cluster health, and keep Kubernetes versions updated.
Code Example:
# Check resource usage
kubectl top nodes
kubectl top pods
# View events
kubectl get events
# Check rollout status
kubectl rollout status deployment/my-app