k8s yaml文件說明
阿新 • • 發佈:2018-11-30
dep erp 9.1 nta png text ava size 是否 nginx yaml文件說明
--- #定義nginx命名空間 apiVersion: v1 kind: Namespace metadata: name: k8s-nginx #自定義的命名空間 --- #定義nginx service apiVersion: v1 kind: Service metadata: name: k8s-nginx namespace: k8s-nginx labels: app: k8s-nginx spec: type: NodePort ports: - port: 80 #分配集群ip的端口 targetPort: 80 #分配pod端口 nodePort: 10280 #node節點端口 protocol: TCP clusterIP: 169.169.249.80 #分配集群ip selector: app: k8s-nginx --- #創建 deployment apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deploy namespace: k8s-nginx labels: app: k8s-nginx spec: replicas: 2 #生成復本數量為2 selector: matchLabels: app: k8s-nginx template: metadata: labels: app: k8s-nginx annotations: app: nginx-clouster spec: containers: - name: nginx image: docker.io/nginx imagePullPolicy: IfNotPresent resources: limits: cpu: 300m memory: 3000Mi requests: cpu: 100m memory: 100Mi ports: - containerPort: 80
如果要修改nginx.yaml文件,二種方式
第一種:
直接修改 nginx.yaml並保存
kubectl apply -f nginx.yaml
第二種:
先查看要修改的資源對象
#kubectl get pod,svc,deploy -n k8s-nginx NAME READY STATUS RESTARTS AGE pod/nginx-deploy-5d677c4495-5wmf2 1/1 Running 0 26m pod/nginx-deploy-5d677c4495-lzv6g 1/1 Running 0 37m pod/nginx-deploy-5d677c4495-rpfgg 1/1 Running 0 37m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/k8s-nginx NodePort 169.169.249.80 <none> 80:10280/TCP 42m NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deployment.extensions/nginx-deploy 3 3 3 3 39m
然後再執行以下命令
kubectl edit deployment.extensions/nginx-deploy -n k8s-nginx
直接編輯,完成後保存,保存後要查看是否出錯,如果沒有出錯會立即生效,如果有出錯,下面會出現error字樣,並在/tmp下生成一個臨時文件,此時原文件並沒有修改,不會影響線上業務
k8s yaml文件說明