Write kubernets yaml files to deploy nginx:1.25 and expose usign service
- User
Write kubernets yaml files to deploy nginx:1.25 and expose usign service
- Assistant
Here is an example Kubernetes YAML deployment file to deploy nginx:1.25 and expose it using a service:
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: selector: matchLabels: app: nginx replicas: 1 template: metadata: labels: app: nginx spec: containers: - name: nginx-container image: nginx:1.25 ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: nginx-service spec: selector: app: nginx ports: - name: http port: 80 targetPort: 80 type: ClusterIPExplanation:
The Deployment object specifies how many replicas of the nginx:1.25 container to deploy and how to configure them. The
replicasfield is set to1, meaning that only one replica of the container will be running. Theselectorfield tells Kubernetes to manage the pods with the label , which matches the labels defined in the container spec.