WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

DevOps · Expert · question 66 of 100

How have you used container orchestration platforms like Kubernetes or Docker Swarm in your past projects? What complex tasks have you automated using these tools?

📕 Buy this interview preparation book: 100 DevOps questions & answers — PDF + EPUB for $5

As an expert DevOps Engineer, I have used container orchestration platforms like Kubernetes and Docker Swarm in multiple projects to streamline deployment, scaling, and management of containerized applications. I’ll describe my experiences in detail for a couple of projects where I utilized these tools.

**Project 1: Microservice-based Application Deployment using Kubernetes**

In this project, I automated the deployment of a microservices-based application on a Kubernetes cluster. The application had multiple services that needed to communicate with one another, and Kubernetes’ built-in functionalities facilitated this communication seamlessly.

1. _Deployment Configuration:_ I created multiple Deployment manifests for each service, specifying the desired state of the application. The Kubernetes Deployments controlled the creation, update, and rollback of containers running the services.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-service
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-service
  template:
    metadata:
      labels:
        app: my-service
    spec:
      containers:
      - name: my-service
        image: my-service:1.0.0
        ports:
        - containerPort: 8080

2. _Service Configuration:_ For each service in the cluster, I created a Kubernetes service to expose it to other services and/or external requests. Services provided load balancing and enabled communication among the microservices.

kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  selector:
    app: my-service
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080

3. _Ingress Configuration:_ To expose the application to the internet, I created an Ingress resource, providing external access and TLS termination with automatic certificate management using cert-manager for HTTPS communication.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    cert-manager.io/issuer: "letsencrypt-prod"
spec:
  rules:
  - host: myservice.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-service
            port:
              number: 80
  tls:
  - hosts:
    - myservice.example.com
    secretName: myservice-tls

4. _Horizontal Pod Autoscaler:_ I set up autoscaling for the application services so they can scale up or down based on the CPU usage or custom metrics. Additionally, Cluster Autoscaler was configured to adjust the size of the cluster based on demand.

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: my-service
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-service
  minReplicas: 3
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70

**Project 2: Scalable Web Application using Docker Swarm**

In this project, I orchestrated a multi-tier web application using Docker Swarm. I deployed the Dockerized application components, including a web server, an application server, and a database server, on a cluster of nodes with built-in load balancing, and autoscaling using Docker services.

1. _Initializing the Swarm:_ I created a Docker Swarm by initializing a node as the swarm manager and adding additional worker nodes.

docker swarm init --advertise-addr <manager-ip>
docker swarm join --token <join-token> <manager-ip>:2377

2. _Creating an Overlay Network:_ I created an overlay network to facilitate communication between the Docker services across different nodes in the Swarm.

docker network create --driver overlay --attachable mynet

3. _Deploying Services:_ For each component of the application, I deployed Docker services using ‘docker service create‘ with the replica count, desired network, and other necessary configurations.

# Web server
docker service create --name web 
--publish 80:80 
--network mynet 
--replicas 3 
my-web-image

# Application server
docker service create --name app 
--publish 8080:8080 
--network mynet 
--replicas 3 
my-app-image

# Database server
docker service create --name db 
--publish 3306:3306 
--network mynet 
--mount type=volume,source=mydata,destination=/var/lib/mysql 
--with-registry-auth 
my-db-image

4. _Autoscaling:_ I monitored the resource utilization of the services and adjusted the replica count as necessary, either manually or by using custom automation scripts. Docker Swarm does not automatically scale the services based on specific metrics, unlike Kubernetes.

docker service scale web=5 app=4

**Conclusion**

In these projects, container orchestration platforms like Kubernetes and Docker Swarm helped me automate complex tasks like service discovery, scaling, load balancing, and network management, enabling smooth deployment and maintenance of containerized applications.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic DevOps interview — then scores it.
📞 Practice DevOps — free 15 min
📕 Buy this interview preparation book: 100 DevOps questions & answers — PDF + EPUB for $5

All 100 DevOps questions · All topics