[goole-gke]nginx-ingress建立测试

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

上一篇:k8s之storageclass和MySQL主从


下一篇:Helm一键式部署注意点