Complete the code to create a LoadBalancer service in Kubernetes.
kind: Service apiVersion: v1 metadata: name: my-service spec: type: [1] selector: app: my-app ports: - protocol: TCP port: 80 targetPort: 8080
The LoadBalancer type exposes the service externally using a cloud provider's load balancer.
Complete the code to define an Ingress resource for routing HTTP traffic.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: [1]
port:
number: 80The Ingress backend must point to a service name, not pods or nodes.
Fix the error in the service type to expose the app externally.
apiVersion: v1 kind: Service metadata: name: web-service spec: type: [1] selector: app: web ports: - port: 80 targetPort: 8080
To expose the service externally with a cloud load balancer, use LoadBalancer type.
Fill both blanks to create an Ingress rule that routes traffic to the correct service and port.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
spec:
rules:
- host: app.example.com
http:
paths:
- path: /app
pathType: Prefix
backend:
service:
name: [1]
port:
number: [2]The Ingress routes to app-service on port 80.
Fill all three blanks to define a LoadBalancer service with the correct selector and port.
apiVersion: v1 kind: Service metadata: name: [1] spec: type: LoadBalancer selector: app: [2] ports: - protocol: TCP port: [3] targetPort: 8080
The service is named frontend-service, selects pods labeled frontend, and exposes port 80.