解决k8s 1.18.0版本 replicas被弃用问题以及暴露k8s的pods 服务

执行命令kubectl run nginx --image=nginx --replicas=2 --port=80 会反馈
Flag --replicas has been deprecated, has no effect and will be removed in the future. 并且只创建一个nginx 容器实例
在K8S v1.18.0以后,–replicas已弃用 ,推荐用 deployment 创建 pods
vim nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  # 创建2个nginx容器
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

创建kubectl apply -f nginx-deployment.yaml
查看 Pods kubectl get pods / kubectl get deployment,下面是我已经部署好的 nginx 容器实例
get pods
get deployment
暴露出服务 kubectl expose deployment nginx-deployment --port=80 --type=LoadBalancer
查看服务状态(查看对外的端口):kubectl get services
在这里插入图片描述
可以看到k8s把31505端口分配给了两个NGINX

ip name
192.168.18.75 master
192.168.18.65 node1
192.168.18.76 node2

解决k8s 1.18.0版本 replicas被弃用问题以及暴露k8s的pods 服务_第1张图片

参考文献

github:issue
Creating a Deployment

你可能感兴趣的:(k8s,运维,kubernetes,nginx)