Improve user experience in Get Started guide for NGF (#799)

This commit is contained in:
Shaun
2025-07-11 11:58:04 +01:00
committed by GitHub
parent d1bb519ef6
commit a1bb1da511

View File

@ -132,13 +132,76 @@ The YAML code in the following sections can be found in the [cafe-example folder
### Create the application resources
Create the file _cafe.yaml_ with the following contents:
Run the following command to create the file _cafe.yaml_, which is then used to deploy the *coffee* application to your cluster:
{{< ghcode `https://raw.githubusercontent.com/nginx/nginx-gateway-fabric/refs/heads/main/examples/cafe-example/cafe.yaml`>}}
Apply it using `kubectl`:
```shell
```yaml
cat <<EOF > cafe.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: coffee
spec:
replicas: 1
selector:
matchLabels:
app: coffee
template:
metadata:
labels:
app: coffee
spec:
containers:
- name: coffee
image: nginxdemos/nginx-hello:plain-text
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: coffee
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
app: coffee
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tea
spec:
replicas: 1
selector:
matchLabels:
app: tea
template:
metadata:
labels:
app: tea
spec:
containers:
- name: tea
image: nginxdemos/nginx-hello:plain-text
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: tea
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
name: http
selector:
app: tea
EOF
kubectl apply -f cafe.yaml
```
@ -163,13 +226,22 @@ tea-6fbfdcb95d-9lhbj 1/1 Running 0 9s
### Create Gateway and HTTPRoute resources
Create the file _gateway.yaml_ with the following contents:
Run the following command to create the file _gateway.yaml_, which is then used to deploy a Gateway to your cluster:
{{< ghcode `https://raw.githubusercontent.com/nginx/nginx-gateway-fabric/refs/heads/main/examples/cafe-example/gateway.yaml`>}}
Apply it using `kubectl`:
```shell
```yaml
cat <<EOF > gateway.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: gateway
spec:
gatewayClassName: nginx
listeners:
- name: http
port: 80
protocol: HTTP
hostname: "*.example.com"
EOF
kubectl apply -f gateway.yaml
```
@ -190,13 +262,48 @@ gateway-nginx-66b5d78f8f-4fmtb 1/1 Running 0 13s
tea-6fbfdcb95d-9lhbj 1/1 Running 0 31s
```
Create the file _cafe-routes.yaml_ with the following contents:
Run the following command to create the file _cafe-routes.yaml_. It is then used to deploy two *HTTPRoute* resources in your cluster: one each for _/coffee_ and _/tea_.
{{< ghcode `https://raw.githubusercontent.com/nginx/nginx-gateway-fabric/refs/heads/main/examples/cafe-example/cafe-routes.yaml`>}}
Apply it using `kubectl`:
```shell
```yaml
cat <<EOF > cafe-routes.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: coffee
spec:
parentRefs:
- name: gateway
sectionName: http
hostnames:
- "cafe.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /coffee
backendRefs:
- name: coffee
port: 80
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: tea
spec:
parentRefs:
- name: gateway
sectionName: http
hostnames:
- "cafe.example.com"
rules:
- matches:
- path:
type: Exact
value: /tea
backendRefs:
- name: tea
port: 80
EOF
kubectl apply -f cafe-routes.yaml
```