相关的 YAML 文件在:http://timd.cn/code/ingress-demo/
Kubernetes:
xxxxxxxxxx
# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-102 Ready <none> 28d v1.23.1
master Ready control-plane,master 28d v1.23.1
xxxxxxxxxx
kubectl apply -f namespace.yaml
查看:
xxxxxxxxxx
# kubectl get namespace ingress-nginx
NAME STATUS AGE
ingress-nginx Active 46s
xxxxxxxxxx
kubectl apply -f configmap.yaml
查看:
xxxxxxxxxx
# kubectl -n ingress-nginx get cm nginx-configuration
NAME DATA AGE
nginx-configuration 0 105s
xxxxxxxxxx
kubectl apply -f tcp-services-configmap.yaml
查看:
xxxxxxxxxx
# kubectl -n ingress-nginx get cm tcp-services
NAME DATA AGE
tcp-services 0 36s
xxxxxxxxxx
kubectl apply -f udp-services-configmap.yaml
查看:
xxxxxxxxxx
# kubectl -n ingress-nginx get cm udp-services
NAME DATA AGE
udp-services 0 34s
xxxxxxxxxx
kubectl apply -f rbac.yaml
查看:
x
# 查看账号
kubectl -n ingress-nginx get sa nginx-ingress-serviceaccount
# 查看集群角色
kubectl -n ingress-nginx get ClusterRole nginx-ingress-clusterrole
# 查看角色
kubectl -n ingress-nginx get Role nginx-ingress-role
# 查看集群角色绑定
kubectl -n ingress-nginx get ClusterRoleBinding nginx-ingress-clusterrole-nisa-binding
# 查看角色绑定
kubectl -n ingress-nginx get RoleBinding nginx-ingress-role-nisa-binding
xxxxxxxxxx
kubectl apply -f default-backend.yaml
查看:
xxxxxxxxxx
# 查看 Service
kubectl -n ingress-nginx get svc default-http-backend
# 查看 Deployment
kubectl -n ingress-nginx get deploy default-http-backend
# 查看 Pod
kubectl -n ingress-nginx get pod -l "app=default-http-backend"
xxxxxxxxxx
kubectl apply -f service-nodeport.yaml
查看:
xxxxxxxxxx
# kubectl -n ingress-nginx get svc ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx NodePort 10.105.79.200 <none> 80:30080/TCP,443:30443/TCP 39s
xxxxxxxxxx
kubectl apply -f with-rbac.yaml
查看:
x
# 查看 Deployment
kubectl -n ingress-nginx get deploy nginx-ingress-controller
# 查看 Pod
kubectl -n ingress-nginx get pod -l "app=ingress-nginx"
在集群外执行(其中 192.168.56.101 是 Kubernetes 的任意 Node 的 IP):
xxxxxxxxxx
% curl -I "http://192.168.56.101:30080/healthz"
HTTP/1.1 200 OK
Date: Wed, 30 Nov 2022 06:33:48 GMT
Content-Type: text/html
Content-Length: 0
Connection: keep-alive
kubectl apply -f deploy-demo.yaml
查看:
# 查看 Service
kubectl -n default get svc myapp
# 查看 Deployment
kubectl -n default get deploy myapp-backend-pod
# 查看 Pod
kubectl -n default get pod -l "app=myapp,release=canary"
xxxxxxxxxx
kubectl apply -f ingress-myapp.yaml
查看:
xxxxxxxxxx
kubectl -n default describe ingress ingress-myapp
在集群外执行(其中 192.168.56.102 是 Kubernetes 的任意 Node 的 IP):
xxxxxxxxxx
% curl --resolve "test.com:30080:192.168.56.102" "http://test.com:30080/"
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>
xxxxxxxxxx
root@k8s-101:~/ingress# kubectl -n ingress-nginx get pod -l "app=ingress-nginx"
NAME READY STATUS RESTARTS AGE
nginx-ingress-controller-5f466d6b4d-2wsjs 1/1 Running 0 16m
root@k8s-101:~/ingress# kubectl -n ingress-nginx exec -it nginx-ingress-controller-5f466d6b4d-2wsjs -- /bin/bash
I have no name!@nginx-ingress-controller-5f466d6b4d-2wsjs:/etc/nginx$
进入容器后查看 /etc/nginx/nginx.conf。