Topics Kubernetes Key Components of a Kubernetes Cluster
Back Sign up to track progress

🎯 TL;DR

Kubernetes is a container orchestration system that automates the deployment, scaling, and management of containerized applications. It matters because it simplifies the process of deploying and managing complex applications in a variety of environments. The single most critical insight is that Kubernetes provides a highly scalable and fault-tolerant way to deploy applications.
A container orchestration system like Kubernetes is similar to a train station manager, where the manager ensures that trains (containers) arrive and depart on time, and that the tracks (resources) are utilized efficiently.

🌱 Beginner Zone

What is Kubernetes in Plain English?

Kubernetes is like a highly efficient and organized factory that produces and manages many products (applications) simultaneously. Just as a factory has machines (containers) that work together to produce a product, Kubernetes has nodes (machines) that work together to run applications. The factory manager (Kubernetes) ensures that the machines are working correctly, and that the products are produced on time and with high quality.

Why Should You Learn This?

Learning Kubernetes is essential for any developer or DevOps engineer who wants to deploy and manage complex applications in a scalable and efficient way. Without Kubernetes, deploying and managing applications can be time-consuming and prone to errors. Knowing Kubernetes can help you to break into the field of cloud computing and DevOps, and can also help you to advance in your career.

Prerequisites — What to Know First

  • Containers (e.g., Docker)
  • Container runtimes (e.g., Docker Engine)
  • Cloud computing (e.g., AWS, GCP, Azure)
  • Linux and networking fundamentals
  • Basic programming skills (e.g., Python, Java)

Quick Start — Get It Working in 5 Minutes

# Create a Kubernetes deployment YAML file
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-world
        image: gcr.io/google-samples/hello-app:1.0
        ports:
        - containerPort: 8080
# Apply the YAML file to create the deployment
kubectl apply -f deployment.yaml
# Verify that the deployment is running
kubectl get deployments

Your First Mistake

One common mistake that beginners make when using Kubernetes is not understanding the difference between a pod and a deployment. A pod is a logical host for one or more containers, while a deployment is a way to manage the rollout of new versions of an application. If you try to manage pods directly, you may end up with a mess of unmanaged containers.

📘 What is Kubernetes? (Core Definition)

Kubernetes is an open-source container orchestration system that automates the deployment, scaling, and management of containerized applications. It was first released in 2014 and is now maintained by the Cloud Native Computing Foundation (CNCF). Kubernetes provides a highly scalable and fault-tolerant way to deploy applications, and is widely used in production environments.

⚙️ How It Works Internally [Medium → Expert]

Kubernetes uses a complex system of internal components to manage the deployment and scaling of applications. The main components include:

  1. etcd: a distributed key-value store that stores the state of the cluster.
  2. API server: the central component that handles incoming requests and updates the state of the cluster.
  3. scheduler: responsible for scheduling pods on available nodes.
  4. controller manager: runs and manages control plane components, such as the scheduler and the API server.
  5. node: a machine that runs pods.
    The execution flow of Kubernetes can be summarized as follows:
  6. A user creates a deployment YAML file and applies it to the cluster using the kubectl command.
  7. The API server receives the request and updates the state of the cluster in etcd.
  8. The scheduler is notified of the new deployment and schedules the pods on available nodes.
  9. The controller manager runs the scheduler and ensures that the desired state of the cluster is achieved.
  10. The node runs the pods and reports back to the controller manager.
Input → [API Server] → [etcd] → [Scheduler] → [Node] → Output
              │
         (controller manager)

Kubernetes has undergone significant changes across major versions, with new features and improvements added in each release. For example, Kubernetes 1.14 introduced the kubectl debug command, which allows users to debug pods more easily.

🔑 Core Concepts

  • Pod [🌱 Beginner]: the basic execution unit in Kubernetes, comprising one or more containers.
  • Deployment [⚙️ Medium]: a way to manage the rollout of new versions of an application.
  • Service [⚙️ Medium]: an abstract resource that provides a network identity and load balancing for accessing a group of pods.
  • Persistent Volume [⚙️ Medium]: a resource that represents a piece of networked storage that can be used by pods.
  • ConfigMap [⚙️ Medium]: a resource that stores configuration data as key-value pairs.
  • Secret [⚙️ Medium]: a resource that stores sensitive data, such as passwords or API keys.
  • Ingress [⚙️ Medium]: a resource that provides load balancing and routing for incoming HTTP requests.
  • Node [⚙️ Medium]: a machine that runs pods.
  • Cluster [⚙️ Medium]: a group of nodes that work together to provide a highly available and scalable environment for running applications.

💻 Code Examples

[🌱 Beginner] — Simple Working Example

# Create a Kubernetes deployment YAML file
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-world
        image: gcr.io/google-samples/hello-app:1.0
        ports:
        - containerPort: 8080
# Apply the YAML file to create the deployment
kubectl apply -f deployment.yaml
# Verify that the deployment is running
kubectl get deployments

[⚙️ Medium] — Real-World Usage

# Create a Kubernetes service YAML file
apiVersion: v1
kind: Service
metadata:
  name: hello-world
spec:
  selector:
    app: hello-world
  ports:
  - name: http
    port: 80
    targetPort: 8080
  type: LoadBalancer
# Apply the YAML file to create the service
kubectl apply -f service.yaml
# Verify that the service is running
kubectl get services

[🚀 Expert] — Production-Grade Example

# Create a Kubernetes deployment YAML file with rolling updates
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-world
        image: gcr.io/google-samples/hello-app:1.0
        ports:
        - containerPort: 8080
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
# Apply the YAML file to create the deployment
kubectl apply -f deployment.yaml
# Verify that the deployment is running
kubectl get deployments

// ✅ Correct: The maxSurge and maxUnavailable fields are set to ensure a smooth rolling update.
// ❌ Wrong: The maxSurge and maxUnavailable fields are not set, which can cause downtime during updates.

Anti-Pattern Table

Anti-PatternBad Code SnippetConsequenceCorrect Fix
Not using rolling updatesstrategy: { type: Recreate }Downtime during updatesstrategy: { type: RollingUpdate }
Not setting resource limitsresources: {}Overutilization of resourcesresources: { requests: { cpu: 100m, memory: 128Mi }, limits: { cpu: 200m, memory: 256Mi } }
Not using load balancingtype: ClusterIPInability to scaletype: LoadBalancer
Not monitoring application metricsmetrics: {}Inability to detect issuesmetrics: { cpu: { target: { type: Utilization, averageUtilization: 50 } } }
Not using persistent storagevolumeMounts: []Loss of datavolumeMounts: [ { name: data, mountPath: /data } ]

🚨 Mistakes by Level

[🌱 Beginner Mistakes] — Week 1 pitfalls

  • Not understanding the difference between a pod and a deployment.
  • Not using the correct Kubernetes version.
  • Not setting up a proper development environment.

[⚙️ Medium Mistakes] — First 6 months in production

  • Not monitoring application metrics.
  • Not using load balancing.
  • Not setting resource limits.

[🚀 Expert Mistakes] — Architecture-level decisions that cost months to fix

  • Not designing for high availability.
  • Not using a service mesh.
  • Not implementing proper security measures.

🔍 Code Review Red Flags

  • Flag: Not using rolling updates | Why wrong: Can cause downtime during updates | Fix: Use strategy: { type: RollingUpdate }.
  • Flag: Not setting resource limits | Why wrong: Can cause overutilization of resources | Fix: Use resources: { requests: { cpu: 100m, memory: 128Mi }, limits: { cpu: 200m, memory: 256Mi } }.
  • Flag: Not using load balancing | Why wrong: Can cause inability to scale | Fix: Use type: LoadBalancer.
  • Flag: Not monitoring application metrics | Why wrong: Can cause inability to detect issues | Fix: Use metrics: { cpu: { target: { type: Utilization, averageUtilization: 50 } } }.
  • Flag: Not using persistent storage | Why wrong: Can cause loss of data | Fix: Use volumeMounts: [ { name: data, mountPath: /data } ].

🆚 Comparison with Alternatives

OptionWhen to UseAdvantagesDisadvantagesPerformanceBest For (Level)
KubernetesLarge-scale applicationsHighly scalable, fault-tolerantComplex, steep learning curveHigh[🚀 Expert]
Docker SwarmSmall-scale applicationsEasy to use, simple to deployLimited scalabilityMedium[🌱 Beginner]
Apache MesosLarge-scale applicationsHighly scalable, fault-tolerantComplex, steep learning curveHigh[⚙️ Medium]
Amazon ECSLarge-scale applicationsHighly scalable, fault-tolerantLimited control, vendor lock-inHigh[⚙️ Medium]
Google Cloud RunSmall-scale applicationsEasy to use, simple to deployLimited scalability, vendor lock-inMedium[🌱 Beginner]

Use Kubernetes when you need to deploy large-scale applications that require high scalability and fault tolerance. Use Docker Swarm when you need to deploy small-scale applications that require ease of use and simplicity. Use Apache Mesos when you need to deploy large-scale applications that require high scalability and fault tolerance, but also need more control over the underlying infrastructure. Use Amazon ECS when you need to deploy large-scale applications that require high scalability and fault tolerance, but also need to use AWS services. Use Google Cloud Run when you need to deploy small-scale applications that require ease of use and simplicity, but also need to use Google Cloud services.

🏗️ Real-World Scenarios

  • Situation: A company needs to deploy a large-scale e-commerce application that requires high scalability and fault tolerance.
  • Root Cause: The application requires a highly scalable and fault-tolerant infrastructure to handle large traffic and provide high availability.
  • Solution: Use Kubernetes to deploy the application, with rolling updates and load balancing to ensure high availability and scalability.
  • Outcome: The application is deployed successfully, with high availability and scalability, and the company is able to handle large traffic and provide a good user experience.
  • Lesson: Use Kubernetes to deploy large-scale applications that require high scalability and fault tolerance.
  • Situation: A company needs to deploy a small-scale web application that requires ease of use and simplicity.
  • Root Cause: The application requires a simple and easy-to-use infrastructure to deploy and manage.
  • Solution: Use Docker Swarm to deploy the application, with a simple and easy-to-use interface to manage the deployment.
  • Outcome: The application is deployed successfully, with ease of use and simplicity, and the company is able to manage the deployment with minimal effort.
  • Lesson: Use Docker Swarm to deploy small-scale applications that require ease of use and simplicity.

⚡ Performance & Optimization [🚀 Expert]

Kubernetes provides several features to optimize performance, including:

  • Horizontal Pod Autoscaling: automatically scales the number of pods based on CPU utilization.
  • Vertical Pod Autoscaling: automatically scales the resources allocated to a pod based on CPU and memory utilization.
  • Cluster Autoscaling: automatically scales the number of nodes in the cluster based on CPU utilization.
  • Resource Requests and Limits: allows you to specify the amount of resources that a pod requires, and the maximum amount of resources that it can use.
  • Network Policies: allows you to control the flow of traffic between pods and services.
    Kubernetes also provides several tools to monitor and optimize performance, including:
  • kubectl top: displays the resource usage of pods and nodes.
  • kubectl describe: displays detailed information about pods, nodes, and services.
  • Prometheus: a monitoring system that provides detailed metrics about the cluster.
  • Grafana: a visualization tool that provides dashboards and charts to display metrics.

🔒 Security Considerations

Kubernetes provides several features to secure the cluster, including:

  • Role-Based Access Control (RBAC): allows you to control access to resources based on roles and permissions.
  • Network Policies: allows you to control the flow of traffic between pods and services.
  • Secrets: allows you to store sensitive data, such as passwords and API keys.
  • Pod Security Policies: allows you to control the security settings of pods, such as the use of privileged containers.
    Kubernetes also provides several tools to monitor and secure the cluster, including:
  • kubectl auth: displays information about the authentication configuration of the cluster.
  • kubectl config: displays information about the configuration of the cluster.
  • Audit Logs: provides a record of all actions performed on the cluster.

👁️ Observability [🚀 Expert]

Kubernetes provides several features to monitor and observe the cluster, including:

  • Metrics: provides detailed metrics about the cluster, such as CPU and memory usage.
  • Logs: provides detailed logs about the cluster, such as pod and container logs.
  • Traces: provides detailed traces about the cluster, such as the flow of traffic between pods and services.
    Kubernetes also provides several tools to monitor and observe the cluster, including:
  • Prometheus: a monitoring system that provides detailed metrics about the cluster.
  • Grafana: a visualization tool that provides dashboards and charts to display metrics.
  • New Relic: a monitoring tool that provides detailed metrics and logs about the cluster.
  • Datadog: a monitoring tool that provides detailed metrics and logs about the cluster.

✅ Production Readiness Checklist

  1. [⚙️ Medium] Security: Implement RBAC and Network Policies to control access to resources.
  2. [⚙️ Medium] Monitoring: Implement Prometheus and Grafana to monitor metrics and logs.
  3. [⚙️ Medium] Logging: Implement logging to provide detailed logs about the cluster.
  4. [⚙️ Medium] Backup and Restore: Implement backup and restore to provide data protection.
  5. [⚙️ Medium] High Availability: Implement high availability to provide redundancy and failover.
  6. [⚙️ Medium] Scalability: Implement scalability to provide horizontal and vertical scaling.
  7. [⚙️ Medium] Performance: Implement performance optimization to provide fast and efficient processing.
  8. [⚙️ Medium] Deployment: Implement deployment to provide automated and rolling updates.
  9. [⚙️ Medium] Rollback: Implement rollback to provide automated and rolling back.
  10. [⚙️ Medium] Testing: Implement testing to provide unit and integration testing.
  11. [⚙️ Medium] Validation: Implement validation to provide input and output validation.
  12. [⚙️ Medium] Error Handling: Implement error handling to provide robust and fault-tolerant error handling.
  13. [⚙️ Medium] Alerting: Implement alerting to provide notifications and alerts.
  14. [⚙️ Medium] Notification: Implement notification to provide notifications and alerts.
  15. [⚙️ Medium] Documentation: Implement documentation to provide detailed and accurate documentation.
  16. [⚙️ Medium] Training: Implement training to provide detailed and accurate training.
  17. [⚙️ Medium] Support: Implement support to provide detailed and accurate support.
  18. [⚙️ Medium] Maintenance: Implement maintenance to provide regular and scheduled maintenance.
  19. [⚙️ Medium] Upgrade: Implement upgrade to provide automated and rolling upgrades.
  20. [⚙️ Medium] Disaster Recovery: Implement disaster recovery to provide automated and rolling recovery.

🎯 Interview Q&A — EXACTLY 23 QUESTIONS

5 [🌱 Beginner] — Conceptual, no experience needed

Q1 [🌱 Beginner] What is Kubernetes?

A: Kubernetes is a container orchestration system that automates the deployment, scaling, and management of containerized applications.
Q2 [🌱 Beginner] What is a pod in Kubernetes?
A: A pod is the basic execution unit in Kubernetes, comprising one or more containers.
Q3 [🌱 Beginner] What is a deployment in Kubernetes?
A: A deployment is a way to manage the rollout of new versions of an application.
Q4 [🌱 Beginner] What is a service in Kubernetes?
A: A service is an abstract resource that provides a network identity and load balancing for accessing a group of pods.
Q5 [🌱 Beginner] What is a persistent volume in Kubernetes?
A: A persistent volume is a resource that represents a piece of networked storage that can be used by pods.

5 [⚙️ Medium] — Practical, scenario-based

Q6 [⚙️ Medium] How do you deploy a new version of an application in Kubernetes?

A: You can deploy a new version of an application in Kubernetes by creating a new deployment YAML file and applying it to the cluster using the kubectl command.
Q7 [⚙️ Medium] How do you scale an application in Kubernetes?
A: You can scale an application in Kubernetes by updating the replica count in the deployment YAML file and applying it to the cluster using the kubectl command.
Q8 [⚙️ Medium] How do you monitor an application in Kubernetes?
A: You can monitor an application in Kubernetes by using the kubectl command to display metrics and logs, or by using a monitoring tool such as Prometheus or Grafana.
Q9 [⚙️ Medium] How do you troubleshoot an issue in Kubernetes?
A: You can troubleshoot an issue in Kubernetes by using the kubectl command to display logs and metrics, or by using a troubleshooting tool such as kubectl debug.
Q10 [⚙️ Medium] How do you secure an application in Kubernetes?
A: You can secure an application in Kubernetes by implementing RBAC and Network Policies to control access to resources, and by using secrets to store sensitive data.

5 [🚀 Expert] — Deep internals + debugging

Q11 [🚀 Expert] How does Kubernetes implement rolling updates?

A: Kubernetes implements rolling updates by using a combination of the RollingUpdate strategy and the maxSurge and maxUnavailable fields in the deployment YAML file.
Q12 [🚀 Expert] How does Kubernetes implement load balancing?
A: Kubernetes implements load balancing by using a combination of the LoadBalancer type and the externalTrafficPolicy field in the service YAML file.
Q13 [🚀 Expert] How does Kubernetes implement persistent storage?
A: Kubernetes implements persistent storage by using a combination of the PersistentVolume resource and the PersistentVolumeClaim resource.
Q14 [🚀 Expert] How does Kubernetes implement security?
A: Kubernetes implements security by using a combination of RBAC, Network Policies, and secrets to control access to resources and store sensitive data.
Q15 [🚀 Expert] How does Kubernetes implement monitoring and logging?
A: Kubernetes implements monitoring and logging by using a combination of the kubectl command and monitoring tools such as Prometheus and Grafana.

5 [🏗️ System Design] — Architecture decisions at scale

Q16 [🏗️ System Design] How would you design a highly available and scalable application in Kubernetes?

A: You would design a highly available and scalable application in Kubernetes by using a combination of rolling updates, load balancing, and persistent storage, and by implementing RBAC and Network Policies to control access to resources.
Q17 [🏗️ System Design] How would you design a secure application in Kubernetes?
A: You would design a secure application in Kubernetes by using a combination of RBAC, Network Policies, and secrets to control access to resources and store sensitive data.
Q18 [🏗️ System Design] How would you design a monitored and logged application in Kubernetes?
A: You would design a monitored and logged application in Kubernetes by using a combination of the kubectl command and monitoring tools such as Prometheus and Grafana.
Q19 [🏗️ System Design] How would you design a highly available and scalable database in Kubernetes?
A: You would design a highly available and scalable database in Kubernetes by using a combination of rolling updates, load balancing, and persistent storage, and by implementing RBAC and Network Policies to control access to resources.
Q20 [🏗️ System Design] How would you design a secure and compliant application in Kubernetes?
A: You would design a secure and compliant application in Kubernetes by using a combination of RBAC, Network Policies, and secrets to control access to resources and store sensitive data, and by implementing compliance frameworks such as PCI-DSS and HIPAA.

3 [⚠️ Interviewer Traps] — Questions that sound easy but catch overconfidence

Q21 [⚠️ Interviewer Traps] What is the difference between a pod and a container?

A: A pod is the basic execution unit in Kubernetes, comprising one or more containers, while a container is a lightweight and standalone executable package of software.
Q22 [⚠️ Interviewer Traps] How do you troubleshoot a pod that is not starting?
A: You can troubleshoot a pod that is not starting by using the kubectl command to display logs and metrics, or by using a troubleshooting tool such as kubectl debug.
Q23 [⚠️ Interviewer Traps] How do you secure a pod that is running a sensitive application?
A: You can secure a pod that is running a sensitive application by using a combination of RBAC, Network Policies, and secrets to control access to resources and store sensitive data.

🏋️ Practice Exercises

Exercise 1 [🌱 Beginner] — Conceptual

What is the difference between a pod and a deployment in Kubernetes?

Exercise 2 [⚙️ Medium] — Build It

Create a Kubernetes deployment YAML file that deploys a new version of an application.

Exercise 3 [🚀 Expert] — Debug This

Troubleshoot a pod that is not starting by using the kubectl command and a troubleshooting tool such as kubectl debug.

🗺️ Learning Path

Before This Topic (Prerequisites)

  • Containers (e.g., Docker)
  • Container runtimes (e.g., Docker Engine)
  • Cloud computing (e.g., AWS, GCP, Azure)
  • Linux and networking fundamentals
  • Basic programming skills (e.g., Python, Java)

After This Topic (What to Learn Next)

  • Advanced Kubernetes topics (e.g., rolling updates, load balancing, persistent storage)
  • Monitoring and logging tools (e.g., Prometheus, Grafana)
  • Security frameworks and compliance (e.g., RBAC, PCI-DSS, HIPAA)
  • System design and architecture (e.g., highly available and scalable applications)
  • Containerization (e.g., Docker, rkt)
  • Orchestration (e.g., Kubernetes, Docker Swarm)
  • Cloud computing (e.g., AWS, GCP, Azure)
  • DevOps and continuous integration (e.g., Jenkins, GitLab CI/CD)

📚 Glossary

  • Pod: the basic execution unit in Kubernetes, comprising one or more containers.
  • Deployment: a way to manage the rollout of new versions of an application.
  • Service: an abstract resource that provides a network identity and load balancing for accessing a group of pods.
  • Persistent Volume: a resource that represents a piece of networked storage that can be used by pods.
  • ConfigMap: a resource that stores configuration data as key-value pairs.
  • Secret: a resource that stores sensitive data, such as passwords or API keys.
  • Ingress: a resource that provides load balancing and routing for incoming HTTP requests.
  • Node: a machine that runs pods.
  • Cluster: a group of nodes that work together to provide a highly available and scalable environment for running applications.

📋 Quick Reference Cheat Sheet

  • Keyword: Pod | Definition: The basic execution unit in Kubernetes, comprising one or more containers. [🌱 Beginner]
  • Keyword: Deployment | Definition: A way to manage the rollout of new versions of an application. [⚙️ Medium]
  • Keyword: Service | Definition: An abstract resource that provides a network identity and load balancing for accessing a group of pods. [⚙️ Medium]
  • Keyword: Persistent Volume | Definition: A resource that represents a piece of networked storage that can be used by pods. [⚙️ Medium]
  • Keyword: ConfigMap | Definition: A resource that stores configuration data as key-value pairs. [⚙️ Medium]
  • Keyword: Secret | Definition: A resource that stores sensitive data, such as passwords or API keys. [⚙️ Medium]
  • Keyword: Ingress | Definition: A resource that provides load balancing and routing for incoming HTTP requests. [⚙️ Medium]
  • Keyword: Node | Definition: A machine that runs pods. [⚙️ Medium]
  • Keyword: Cluster | Definition: A group of nodes that work together to provide a highly available and scalable environment for running applications. [⚙️ Medium]
  • Keyword: Rolling Update | Definition: A way to update a deployment by rolling out a new version of the application. [⚙️ Medium]
  • Keyword: Load Balancing | Definition: A way to distribute traffic across multiple pods. [⚙️ Medium]
  • Keyword: Persistent Storage | Definition: A way to store data persistently across pod restarts. [⚙️ Medium]
  • Keyword: Security | Definition: A way to control access to resources and store sensitive data. [⚙️ Medium]
  • Keyword: Monitoring | Definition: A way to collect metrics and logs about the cluster. [⚙️ Medium]
  • Keyword: Logging | Definition: A way to collect logs about the cluster. [⚙️ Medium]
  • Keyword: Troubleshooting | Definition: A way to debug issues in the cluster. [⚙️ Medium]
  • Keyword: Deployment Strategies | Definition: A way to manage the rollout of new versions of an application. [⚙️ Medium]
  • Keyword: Scaling | Definition: A way to increase or decrease the number of pods in a deployment. [⚙️ Medium]
  • Keyword: High Availability | Definition: A way to ensure that the cluster is always available and can handle failures. [⚙️ Medium]
  • Keyword: Scalability | Definition: A way to increase or decrease the resources allocated to a deployment. [⚙️ Medium]
  • Keyword: Performance Optimization | Definition: A way to optimize the performance of the cluster. [⚀ Expert]
Yaml Code Example
```yml
# Create a Kubernetes deployment YAML file with rolling updates
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-world
        image: gcr.io/google-samples/hello-app:1.0
        ports:
        - containerPort: 8080
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
---
# Create a Kubernetes service YAML file
apiVersion: v1
kind: Service
metadata:
  name: hello-world
spec:
  selector:
    app: hello-world
  ports:
  - name: http
    port: 80
    targetPort: 8080
  type: LoadBalancer
```
```bash
# Apply the YAML file to create the deployment
kubectl apply -f deployment.yaml
# Verify that the deployment is running
kubectl get deployments
# Apply the YAML file to create the service
kubectl apply -f service.yaml
# Verify that the service is running
kubectl get services
```
// ✅ Correct: The `maxSurge` and `maxUnavailable` fields are set to ensure a smooth rolling update.
// ❌ Wrong: The `maxSurge` and `maxUnavailable` fields are not set, which can cause downtime during updates.
Done reading this topic? Sign up free to track your progress.
Sign Up to Track