Deployment(部署)
Deployment处于master节点,master会选择合适的work节点创建Container
Container会被包含在Pod中
通过k8s部署一个nginx
kubectl create deployment my-nginx --image=nginx
创建一个tomcat 镜像
创建一个tomcat-svc.yaml文件 创建service类型的资源
apiVersion: v1
kind: Service
metadata:
name: tomcat
spec:
type: NodePort
ports:
- port: 8080
nodePort: 30080
selector:
app: tomcat
部署进k8s集群
kubectl create -f tomcat-svc.yaml
创建一个ingress 类型的规则
ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-nginx
namespace: ingress-nginx
spec:
rules: # 一个ingress可以配置多个rules
- host: k1.devops.com # 域名配置,可以不写,匹配*,或者写 *.bar.com
http:
paths: # 相当于nginx的location,同一个host可以配置多个path
- path: "/nginx-1"
pathType: Prefix
backend:
service:
name: tomcat # 代理到哪个svc 确保要有这个镜像和端口
port:
number: 8080 # svc port need to privode