apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
namespace: cjy-test
spec:
replicas: 1
selector: #标签选择器
matchLabels: #匹配的标签为
app: myapp
release: canary
template:
metadata:
labels:
app: myapp #和上面的myapp要匹配
release: canary
spec:
containers:
- name: myapp
image: ikubernetes/myapp:v1
ports:
- name: http
containerPort: 80
apiVersion: v1
kind: Service
metadata:
name: myapp-svc
namespace: cjy-test
spec:
selector:
app: myapp #挑选的pod还是myapp。一个pod可以有多个service
release: canary
clusterIP: None #None表示是无头service
ports:
- port: 39320 #service ip中的端口
targetPort: 80 #容器ip中的端口
kind: Service
apiVersion: v1
metadata:
name: myapp-svcname
namespace: cjy-test
spec:
type: ExternalName
externalName: myapp-svc.cjy2-test.svc.cluster.local
在另一个名称空间的创建方式同上三步