标签: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
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 获取
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,说明部署成功
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>
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>
标签:ingress kubernetes ingress ingress-controlle
原文地址:http://blog.51cto.com/2759492/2087931