service.yaml
[root@master templates]# kubectl create deployment web1 --image=nginx --dry-run -o yaml > deployment.yamlW0611 16:53:59.635980 32639 helpers.go:553] --dry-run is deprecated and can be replaced with --dry-run=client.
[root@master templates]# ls
deployment.yaml
[root@master templates]# cat deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web1
name: web1
spec:
replicas: 1
selector:
matchLabels:
app: web1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web1
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
[root@master templates]# kubectl create deployment web1 --image=nginx #先创建web1 ,然后再执行下面的service.yaml
deployment.apps/web1 created
[root@master templates]# kubectl get pods
[root@master templates]# kubectl expose deployment web1 --port=80 --target-port=80 --type=NodePort --dry-run -o yaml > service.yaml
W0611 16:59:07.608904 2461 helpers.go:553] --dry-run is deprecated and can be replaced with --dry-run=client.
[root@master templates]# ls
deployment.yaml service.yaml
[root@master templates]# vi service.yaml
#然后再删除web1
[root@master templates]# kubectl delete deployment web1
deployment.apps "web1" deleted
[root@master templates]# kubectl get pods
[root@master templates]# ls
deployment.yaml service.yaml