Deployment
# app-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: app-web
spec:
selector:
matchLabels:
app: app-web-v1
replicas: 3
template:
metadata:
labels:
app: app-web-v1
spec:
containers:
- name: myapp
image: zzzwangjun/apps:v1
ports:
- containerPort: 80
SVC
# app-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: app-svc
spec:
selector:
app: app-web-v1
ports:
- protocol: TCP
port: 8200
targetPort: 80
Ingress Ningx
- Ingress主要实现集群内所有服务的入口,通过一系列规则集合来允许外部的访问。
- Ingress可以配置为提供服务外部访问的URL,负载均衡,SSL,提供基于名称的虚拟主机等。而ingress的具体实现是由ingress Controller实现。
Ingress Ningx 官网
下载 mandatory.yaml
kubectl create -f mandatory.yaml
通过NodePort方式暴露
# service-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
- name: https
port: 443
targetPort: 443
protocol: TCP
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx