kubernetes yaml文件学习

先生成两个yaml文件

nginx-deployment.yml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3   
  strategy:
    rollingUpdate:  
      maxSurge: 1         #滚动升级时最大同时升级1个pod
      maxUnavailable: 1   #滚动升级时最大允许不可用的pod个数
  template:
    metadata:
      labels:
        run: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.7.9
          ports:
            - containerPort: 80
          resources:               #资源管理,请求请见http://blog.csdn.net/liyingke112/article/details/77452630
              requests:            #容器运行时,最低资源需求,也就是说最少需要多少资源容器才能正常运行  
                cpu: 0.1           #CPU资源(核数),两种方式,浮点数或者是整数+m,0.1=100m,最少值为0.001核(1m)
                memory: 32Mi       #内存使用量  
              limits:              #资源限制  
                cpu: 0.5  
                memory: 32Mi

nginx-service.yml

apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec:
  type: NodePort
  selector:
    run: nginx
  ports:
  - protocol: TCP       #端口协议,支持TCP和UDP,默认TCP
    nodePort: 30000     #当type = NodePort时,指定映射到物理机的端口号
    port: 8080          #服务监听的端口号
    targetPort: 80      #需要转发到后端Pod的端口号
  # status:                                #当spce.type=LoadBalancer时,设置外部负载均衡器的地址
  #   loadBalancer:                        #外部负载均衡器
  #     ingress:                           #外部负载均衡器
  #       ip: string                       #外部负载均衡器的Ip地址值
  #       hostname: string                 #外部负载均衡器的主机名

命令行处理

kubectl apply -f nginx-deployment.yml
kubectl apply -f nginx-service.yml

最后骑过http://localhost:30000/查看结果

猜你喜欢

转载自www.cnblogs.com/weschen/p/12658892.html
今日推荐