码迷,mamicode.com
首页 > Web开发 > 详细

kubernetes Ingress网络配置说明

时间:2018-03-17 17:52:18      阅读:804      评论:0      收藏:0      [点我收藏+]

标签:ingress   kubernetes ingress   ingress-controlle   

docker镜像地址

默认后端服务镜像: registry.cn-qingdao.aliyuncs.com/kube8s/defaultbackend:1.0
nginx-Ingress-controller服务镜像:registry.cn-qingdao.aliyuncs.com/kube8s/nginx-ingress-controller:0.8.3
测试服务镜像:registry.cn-qingdao.aliyuncs.com/icommon/hello-world:latest


部署Ingress-controlle默认后端服务

1.配置文件

$ cat default-http-backend.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: default-http-backend
  namespace: kube-system
spec:
  replicas: 1
  selector:
    k8s-app: default-http-backend
  template:
    metadata:
      labels:
        k8s-app: default-http-backend
    spec:
      terminationGracePeriodSeconds: 60
      containers:
      - name: default-http-backend
        image: registry.cn-qingdao.aliyuncs.com/kube8s/defaultbackend:1.0 
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 30
          timeoutSeconds: 5
        ports:
        - containerPort: 8080
        resources:
          limits:
            cpu: 10m
            memory: 20Mi
          requests:
            cpu: 10m
            memory: 20Mi

---

apiVersion: v1
kind: Service
metadata:
  name: default-http-backend
  labels:
    k8s-app: default-http-backend
  namespace: kube-system
spec:
  ports:
  - port: 80
    targetPort: 8080
  selector:
    k8s-app: default-http-backend

2.启动服务

kubectl create -f default-http-backend.yaml

3.验证

curl http://$pod_ip:8080/healthz

返回OK,说明部署成功
pod_ip,可以使用kubectl describe 获取


部署nginx-Ingress-controller服务

1.配置文件

$ cat ingress-controller.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx-ingress-controller
  namespace: kube-system
  labels:
    k8s-app: nginx-ingress-lb
spec:
  replicas: 1
  selector:
    k8s-app: nginx-ingress-lb
  template:
    metadata:
      labels:
        k8s-app: nginx-ingress-lb
        name: nginx-ingress-lb
    spec:
      #跟apiserver通信采用的serviceaccount不是默认的default,需要一个token,serviceaccount文件见下面
      serviceAccount: admin-user
      serviceAccountName: admin-user
      hostNetwork: true     #解决端口无法映射问题
      terminationGracePeriodSeconds: 60
      containers:
      - image: registry.cn-qingdao.aliyuncs.com/kube8s/nginx-ingress-controller:0.8.3
        name: nginx-ingress-lb
        readinessProbe:
          httpGet:
            path: /healthz
            port: 80
            scheme: HTTP
        livenessProbe:
          httpGet:
            path: /healthz
            port: 80
            scheme: HTTP
          initialDelaySeconds: 10
          timeoutSeconds: 1
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: KUBERNETES_MASTER
            value: https://192.168.6.110:6443 #kubeapiserver 地址
        ports:
        - containerPort: 80
          hostPort: 80
        - containerPort: 443
          hostPort: 443
        args:
        - /nginx-ingress-controller
        - --default-backend-service=$(POD_NAMESPACE)/default-http-backend

serviceAccount文件

$ cat admin-user.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kube-system

2.启动服务

kubectl create -f admin-user.yaml
kubectl create -f ingress-controller.yaml

3.验证

curl http://$node_ip:8080/healthz

返回OK,说明部署成功


部署hello-world测试服务

1.配置文件

$cat hello-world.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: hello-world 
spec:
  replicas: 3
  template:
    metadata:
      labels:
        k8s-app: hello-world 
    spec:
      containers:
      - name: hello-world 
        image: registry.cn-qingdao.aliyuncs.com/icommon/hello-world:latest 
---
apiVersion: v1
kind: Service
metadata:
  name: hello-world 
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8080
        nodePort: 31180
  selector:
    k8s-app: hello-world

2.启动服务

kubectl create -f hello-world.yaml

3.验证服务

curl http://$node_ip:31180/hello-world/index.jsp

返回以下内容,说明成功部署

<html>
<body>
<h1>Hello World?</h1>
<h2>Hello World!</h2>
</body>
</html>

部署Ingress服务

1.配置文件

$ cat ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-ingress
spec:
  rules:
     - http:
        paths:
        - path: /hello-world/index.jsp
          backend:
            serviceName: hello-world
            servicePort: 8080

2.启动服务

kubectl create -f ingress.yaml

3.验证

curl http://$node_ip/hello-world/index.jsp

返回以下内容,说明成功部署

<html>
<body>
<h1>Hello World?</h1>
<h2>Hello World!</h2>
</body>
</html>

kubernetes Ingress网络配置说明

标签:ingress   kubernetes ingress   ingress-controlle   

原文地址:http://blog.51cto.com/2759492/2087931

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!