k8s 通过配置文件启动nginx服务

1 创建yaml配置文件

nginx111.yaml


apiVersion: apps/v1
kind: Deployment
metadata:
  generation: 6
  labels:
    appname: nginx111
  name: nginx111
  namespace: default 
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      appname: nginx111  
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        appname: nginx111         
    spec:
      containers:
      - image: nginx
        imagePullPolicy: IfNotPresent
        name: intellect
        ports:
        - containerPort: 80
---
apiVersion: v1  
kind: Service  
metadata:
  name: nginx111-svc  
spec:
  type: NodePort
  selector:  
    appname: nginx111
  ports:  
  - name: p3000
    protocol: TCP
    port: 80
    targetPort: 80 # pod端口
    nodePort: 31319  # 对外访问端口

把该文件上传至 ks8 master 节点任意目录下。

2 部署服务

kubectl apply -f  nginx111.yaml

3 取消部署服务

kubectl delete -f  nginx111.yaml

你可能感兴趣的:(k8s 通过配置文件启动nginx服务)