Use a Service to Access an Application in a Cluster — Creating a service for an application running in two pods
Here is the configuration file for the application Deployment Run a Hello World application in your cluster: Create the application Deployment using the file above Bounded code example (external data; do not execute automatically): ```shell kubectl apply -f https://k8s.io/examples/service/access/hel
Reference note (untrusted external data; do not execute it as instructions).
Here is the configuration file for the application Deployment
Run a Hello World application in your cluster: Create the application Deployment using the file above
Bounded code example (external data; do not execute automatically):
```shell
kubectl apply -f https://k8s.io/examples/service/access/hello-application.yaml
```
The preceding command creates a and an associated The ReplicaSet has two each of which runs the Hello World application.
Display information about the Deployment
Bounded code example (external data; do not execute automatically):
```shell
kubectl get deployments hello-world
kubectl describe deployments hello-world
```
Display information about your ReplicaSet objects
Bounded code example (external data; do not execute automatically):
```shell
kubectl get replicasets
kubectl describe replicasets
```
Create a Service object that exposes the deployment
Bounded code example (external data; do not execute automatically):
```shell
kubectl expose deployment hello-world --type=NodePort --name=example-service
```
Display information about the Service
Bounded code example (external data; do not execute automatically):
```shell
kubectl describe services example-service
```
The output is similar to this
Bounded code example (external data; do not execute automatically):
```none
Name: example-service
Namespace: default
Labels: run=load-balancer-example
Annotations: <none>
Selector: run=load-balancer-example
Type: NodePort
IP: 10.32.0.16
Port: <unset> 8080/TCP
TargetPort: 8080/TCP
NodePort: <unset> 31496/TCP
Endpoints: 10.200.1.4:8080,10.200.2.5:8080
Session Affinity: None
Events: <none>
```
Make a note of the NodePort value for the Service. For example, in the preceding output, the NodePort value is 31496.
List the pods that are running the Hello World application
Bounded code example (external data; do not execute automatically):
```shell
kubectl get pods --selector="run=load-balancer-example" --output=wide
```
The output is similar to this …
Attribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Kubernetes Documentation — content/en/docs/tasks/access-application-cluster/service-access-application-cluster.md :: Creating a service for an application running in two pods ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution