Home > Archives > Ingress示例

Ingress示例

Publish:


---
# ingress-example-1.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-1
spec:
  rules:
  - http:
      paths:
	  - path: /test
	    backend:
		  serviceName: test
		  servicePort: 80
		  
kubectl create -f ingress-example-1.yaml
kubectl get ing

---
# ingress-example-2.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-2
spec:
  rules:
  - host: helloworld-v1.example.com
    http:
	  paths:
	  - path: /
	    backend:
		  serviceName: helloworld-v1
		  servicePort: 80
  - host: helloworld-v2.example.com
    http:
	  paths:
	  - path: /
	    backend:
		  serviceName: helloworld-v2
		  servicePort: 80
		  
kubectl create -f ingress-example-2.yaml
kubectl get ing

---
# ingress-ssl-sceret.yaml
apiVersion: v1
data:
  tls.crt: base64_encoded_cert
  tls.key: base64_encoded_key
kind: Secret
metadata:
  name: ssh-secret
  namespace: default
type: Opaque

# ingress-example-3.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: example-3
spec:
  tls:
  - secretName: ssh-secret
  backend:
    serviceName: apiservice
    servicePort: 80
	
---
# helloworld-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: helloworld-pod
  labels:
    app: helloworld-pod
    tier: backend
spec:
  containers:
  - name: api-server
    image: baoguoding/demo
    ports:
    - containerPort: 3000
	   
kubectl create -f helloworld-pod.yaml

# helloworld-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: helloworld-service
spec:
  ports:
  - port: 3000
    protocol: TCP
    targetPort: 3000
  selector:
    app: helloworld-pod

kubectl create -f helloworld-service.yaml
kubectl get all

---

curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/namespace.yaml | kubectl apply -f -

curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/default-backend.yaml | kubectl apply -f -

curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/configmap.yaml | kubectl apply -f -

curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/tcp-services-configmap.yaml | kubectl apply -f -

curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/udp-services-configmap.yaml | kubectl apply -f -

curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/without-rbac.yaml | kubectl apply -f -

kubectl get all -n ingress-nginx

---
# helloworld-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: helloworld-ingress
  namespace: default
spec:
  rules:
  - host: helloworld.example.com
    http:
      paths:
      - backend:
          serviceName: helloworld-service
          servicePort: 3000
		  
---

Enable ingress on Cluster

vim /etc/host
127.0.0.1 localhost
<IP> helloworld.example.com

---
curl http://helloworld.example.com/

curl http://<IP>

参考

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo