1、google賬號選擇
gcloud init
# 注需要googlecloud權限
2、鏈接對應gke集羣
gcloud container clusters get-credentials <集羣名> --zone <地區> --project <項目>
3、helm安裝
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
3、建立靜態賬號
gcloud compute addresses create ingress-test-static-ip-address
4、建立namespace
cat ingress-namespace.yaml apiVersion: v1 kind: Namespace metadata: name: ingress-nginx # 執行 kubectl create -f ingress-namespace.yaml
5、靜態IP啓動service和ingress
helm install nginx-ingress ingress-nginx/ingress-nginx --namespace ingress-nginx --set controller.service.loadBalancerIP=<靜態IP>
6、測試ingress
cat ingress-resource.yaml apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: ingress-hello annotations: kubernetes.io/ingress.class: "nginx" nginx.ingress.kubernetes.io/ssl-redirect: "false" spec: rules: - host: "k8s-hello.k8s123.com" http: paths: - pathType: Prefix path: "/hello" backend: service: name: hello-app port: number: 8080 kubectl apply -f ingress-resource.yaml
訪問:
http://k8s-hello.k8s123.com/hello