kubernete实战篇-Deployment部署
        
      
     
    
   
   我们以部署一个可访问http服务的为例,涉及的知识点:
- ConfigMap
 
- Service
 
- Deployment
 
- kubectl port-forward
 
编写yaml
 
  apiVersion: v1 kind: ConfigMap metadata:    name: sai-config  data:   config.yaml: |-     name: sai0556     mode: debug     addr: :8080     hi: w~o~w
  ---
  apiVersion: v1 kind: Service metadata:   name: sai   labels:      app: sai spec:    ports:   - protocol: TCP     port: 80      targetPort: 8080    selector:      app: sai
  ---
  apiVersion: apps/v1 kind: Deployment metadata:   name: sai spec:   replicas: 1    selector:      matchLabels:        app: sai   template:      metadata:       labels:         app: sai     spec:       containers:       - name: sai         image: 	puresai/k8s-configmap-sai:0.2         imagePullPolicy: IfNotPresent         command:           - '/app/puresai'         volumeMounts:            - name: config             mountPath: /app/config.yaml             readOnly: true             subPath: config.yaml       volumes:          - name: config           configMap:             defaultMode: 0600             name: sai-config
 
  | 
 
应用
kubectl apply -f sai-config.yaml
   | 
 
测试
使用 kubectl 查看
kubectl get deployment kubectl get service
   | 
 

测试:
 kubectl port-forward svc/sai 8088:80
 
  | 
 

可以看到请求是成功! http://127.0.0.1:8088/
当然,也可以使用  NodePort 
apiVersion: v1 kind: Service metadata:   name: sai   labels:      app: sai spec:    type: NodePort   ports:   - protocol: TCP     port: 8080     nodePort: 31080   selector:     app: sai
   | 
 
