go語言工程製作yaml檔案,並部署到kubernetes
阿新 • • 發佈:2019-01-01
前言
在這篇文章中,筆者將講下如何將go工程的docker映象部署到kubernetes。
1.製作yaml檔案
首先基於現有的docker映象,製作出deployment和service。
apiVersion: v1
items:
- apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mygohttp
labels:
app: mygohttp
spec:
replicas: 1
template:
metadata:
labels:
app: mygohttp
spec:
containers:
- name: mygohttp
image: mygohttp:latest
imagePullPolicy: IfNotPresent
env:
- name: TASKID
value: "hi"
ports:
- containerPort: 8080
resources:
limits:
cpu: 1000m
memory: 1Gi
requests:
cpu: 1000m
memory: 1Gi
- apiVersion: v1
kind: Service
metadata:
name: mygohttp
labels:
app: mygohttp
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
selector:
app: mygohttp
kind: List
metadata: {}
注意kubernetes**傳遞系統**引數採用 如下方式:
env:
- name: TASKID
value: "hi"
2.部署mygohttp服務
kubectl create -f kube-mygohttp.yaml
輸出:
deployment "mygohttp" created
service "mygohttp" created
3.刪除mygohttp服務
kubectl delete -f kube-mygohttp.yaml
輸出:
deployment "mygohttp" deleted
service "mygohttp" deleted
總結
至此筆者已經講完整個部署流程,希望大家能有所收穫。