Create a simple NGINX service

Last updated:2021-04-14 15:43:53

This topic describes how to create a simple NGINX Service in a Kingsoft Cloud container cluster.

Create an NGINX application

Create a Deployment

Use kubectl to run the following command:

kubectl run my-nginx --image=nginx --replicas=3 --port=80
deployment "my-nginx" created

The command creates a my-nginx Deployment that contains three NGINX containers.

Query the status of the NGINX containers.

kubectl get pod
NAME                                 READY     STATUS              RESTARTS   AGE
my-nginx-85584476c8-7nsnr            1/1       Running             0          1m
my-nginx-85584476c8-k86pj            1/1       Running             0          1m
my-nginx-85584476c8-p8kvb            1/1       Running             0          1m

Create a Service

kubectl expose deployment my-nginx --port=80 --type=LoadBalancer
service "my-nginx" exposed

The command creates a LoadBalancer Service for the NGINX application to expose the NGINX Service to the Internet.

View the Service

Run the following command to view the Service:

kubectl get svc
NAME       TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)        AGE
my-nginx   LoadBalancer   10.254.xx.xx   120.92.xx.xx   80:31084/TCP   8s

The NGINX Service is available at 120.92.xx.xx, as shown in the following figure.

image.png

Did you find the above information helpful?

Unhelpful
Mostly Unhelpful
A little helpful
Helpful
Very helpful

What might be the problems?

Insufficient
Outdated
Unclear or awkward
Redundant or clumsy
Lack of context for the complex system or functionality

More suggestions

0/200

Please give us your feedback.

Submitted

Thank you for your feedback.

问题反馈