kubernetes ingress-nginx 0.15.0使用

1 創建相關資源

# kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml

此時ingress-nginx-controller還不能使用,container日誌顯示缺少ingress-nginx服務。

2 創建ingress-nginx服務

# kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/provider/baremetal/service-nodeport.yaml

3 測試

# kubectl get svc  -o wide -n ingress-nginx
NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE       SELECTOR
default-http-backend   ClusterIP   10.104.183.167   <none>        80/TCP         1h        app=default-http-backend
ingress-nginx          NodePort    10.108.244.205   <none>        80:32483/TCP   52m       app=ingress-nginx

# cat << EOF | kubectl create -f -
apiVersion: apps/v1beta1
kind: Deployment
metadata: 
  name: hello-world-deployment
spec: 
  replicas: 1
  template: 
    metadata: 
      labels: 
        app: hello-world
    spec: 
      containers: 
        - image: "gokul93/hello-world:latest"
          imagePullPolicy: Always
          name: hello-world-container
          ports: 
            - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata: 
  name: hello-world-svc
spec: 
  ports: 
     -  port: 8080
        protocol: TCP
        targetPort: 8080
  selector: 
    app: hello-world
  type: NodePort
EOF

# cat << EOF | kubectl create -f -
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
  creationTimestamp: 2018-08-03T02:51:13Z
  generation: 2
  name: hello-world-ingress
  namespace: default
  resourceVersion: "3668608"
  selfLink: /apis/extensions/v1beta1/namespaces/default/ingresses/hello-world-ingress
  uid: 15b9c53b-96c8-11e8-9920-00505683568f
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: hello-world-svc
          servicePort: 8080
        path: /
EOF

# curl k8s-node-ip:32483/hello
Hello world!hello
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章