


kubectl apply -f xx.yaml。apiVersion: apps/v1kind: Deploymentmetadata:name: nginx-v1spec:replicas: 3selector:matchLabels:app: nginxversion: v1template:metadata:labels:app: nginxversion: v1spec:containers:- name: nginximage: "openresty/openresty:centos"ports:- name: httpprotocol: TCPcontainerPort: 80volumeMounts:- mountPath: /usr/local/openresty/nginx/conf/nginx.confname: configsubPath: nginx.confvolumes:- name: configconfigMap:name: nginx-v1---apiVersion: v1kind: ConfigMapmetadata:labels:app: nginxversion: v1name: nginx-v1data:nginx.conf: |-worker_processes 1;events {accept_mutex on;multi_accept on;use epoll;worker_connections 1024;}http {ignore_invalid_headers off;server {listen 80;location / {access_by_lua 'local header_str = ngx.say("nginx-v1")';}}}
apiVersion: apps/v1kind: Deploymentmetadata:name: nginx-v2spec:replicas: 3selector:matchLabels:app: nginxversion: v2template:metadata:labels:app: nginxversion: v2spec:containers:- name: nginximage: "openresty/openresty:centos"ports:- name: httpprotocol: TCPcontainerPort: 80volumeMounts:- mountPath: /usr/local/openresty/nginx/conf/nginx.confname: configsubPath: nginx.confvolumes:- name: configconfigMap:name: nginx-v2---apiVersion: v1kind: ConfigMapmetadata:labels:app: nginxversion: v2name: nginx-v2data:nginx.conf: |-worker_processes 1;events {accept_mutex on;multi_accept on;use epoll;worker_connections 1024;}http {ignore_invalid_headers off;server {listen 80;location / {access_by_lua 'local header_str = ngx.say("nginx-v2")';}}}

apiVersion: v1kind: Servicemetadata:name: nginxspec:type: LoadBalancerports:- port: 80protocol: TCPname: httpselector:app: nginxversion: v1
for i in {1..10}; do curl EXTERNAL-IP; done; # 替换 EXTERNAL-IP 为 Service 的 CLB IP 地址
nginx-v1nginx-v1nginx-v1nginx-v1nginx-v1nginx-v1nginx-v1nginx-v1nginx-v1nginx-v1

selector:app: nginxversion: v2
kubectl patch service nginx -p '{"spec":{"selector":{"version":"v2"}}}'
$ for i in {1..10}; do curl EXTERNAL-IP; done; # 替换 EXTERNAL-IP 为 Service 的 CLB IP 地址
nginx-v2nginx-v2nginx-v2nginx-v2nginx-v2nginx-v2nginx-v2nginx-v2nginx-v2nginx-v2
version 标签,让 Service 同时选中两个版本的 Deployment 的 Pod。YAML 示例如下:apiVersion: v1kind: Servicemetadata:name: nginxspec:type: LoadBalancerports:- port: 80protocol: TCPname: httpselector:app: nginx
for i in {1..10}; do curl EXTERNAL-IP; done; # 替换 EXTERNAL-IP 为 Service 的 CLB IP 地址
nginx-v1nginx-v1nginx-v2nginx-v2nginx-v2nginx-v1nginx-v1nginx-v1nginx-v2nginx-v2
.spec.replicas 修改为1并单击完成。 .spec.replicas 修改为4并单击完成。kubectl scale deployment/nginx-v1 --replicas=1kubectl scale deployment/nginx-v2 --replicas=4
for i in {1..10}; do curl EXTERNAL-IP; done; # 替换 EXTERNAL-IP 为 Service 的 CLB IP 地址
nginx-v2nginx-v1nginx-v2nginx-v2nginx-v2nginx-v2nginx-v1nginx-v2nginx-v2nginx-v2
文档反馈