yaml

使用Deployment控制器部署镜像:
kubectl create deployment web --image=lizhenliang/java-demo
kubectl get deploy,pods
使用Service将Pod暴露出去:
kubectl expose deployment web --port=80 --target-port=8080 --type=NodePort
kubectl get service
访问应用:
http://NodeIP:Port # 端口随机生成,通过get svc获取


vim deployment.yaml                             #可用测试yaml

apiVersion: apps/v1              #API版本
kind: Deployment                 #资源类型
metadata:                        #资源元数据 
   name: nginx-deployment         #deployment名字
   namespace: default             #命名空间
   labels:                        #标签 
     app: nginx                   #标签名字
spec:                            #资源规格
   replicas: 4                    #副本数量
   selector:                      #标签选择器
     matchLabels:
       app: nginx                 #标签名字

  template:                      #Pod模板
     metadata:                    #资源元数据
       labels:                    #标签
         app: nginx               #标签名
     spec:                        #资源规格
       containers:                #容器配置
       - name: nginx
         image: nginx:1.14.2
         #  imagePullPolicy: IfNotPresent   #本地有则使用本地镜像,不拉取(Always:总是拉取镜像,默认策略 Never:只使用本地镜>像, 从不拉取,即使本地没有)
         ports:                   #端口
         - containerPort: 80      #容器端口

        livenessProbe:            #存活检查 应用自修复
           tcpSocket:              #发起TCP Socket建立成功
             port: 80
           initialDelaySeconds: 5  #启动容器后多少秒健康检查
           periodSeconds: 5        #以后间隔多少秒检查一次
         readinessProbe:           #就绪检查
           httpGet:                #发起HTTP请求
             path: /index.html
             port: 80
           initialDelaySeconds: 5
           periodSeconds: 5

         resources:                #资源限制
           requests:
             cpu: 0.2
             memory: 400Mi
           limits:
             cpu: 0.4
             memory: 600Mi

        volumeMounts:            #nfs挂载:容器内目录
         - name: web
           mountPath: /usr/share/nginx/html/
       volumes:                   #nfs服务器目录
       - name: web
         nfs:
           server: 192.168.1.32
           path: /ifs/kubernetes/testweb

      affinity:                  #亲和性配置,保证副本调度到不同节点
           podAntiAffinity:
            requiredDuringSchedulingIgnoredDuringExecution:
            - topologyKey: "kubernetes.io/hostname"
              labelSelector:
                matchLabels:
                  app: nginx

---
apiVersion: v1
kind: Service
metadata:
   name: nginx-svc
   namespace: default
spec:
   ports:
   - port: 89                     #集群内端口
     protocol: TCP
     targetPort: 80               #容器端口
     nodePort:  89                #指定nodeport端口,指定访问端口
   selector:
     app: nginx
   type: NodePort

原文地址:https://www.cnblogs.com/pengrj/p/15741386.html