How to Write Kubernetes Manifests for a Go Service

Create YAML manifests for Deployment and Service resources, then apply them using kubectl to run your Go service in Kubernetes.

Create a deployment.yaml manifest that defines the Go service container, image, and resource limits, then apply it to your cluster.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: go-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: go-service
  template:
    metadata:
      labels:
        app: go-service
    spec:
      containers:
      - name: go-service
        image: my-registry/go-service:latest
        ports:
        - containerPort: 8080
        resources:
          limits:
            cpu: "500m"
            memory: "128Mi"
          requests:
            cpu: "250m"
            memory: "64Mi"

Apply the manifest with:

kubectl apply -f deployment.yaml

Create a service.yaml manifest to expose the deployment:

apiVersion: v1
kind: Service
metadata:
  name: go-service
spec:
  selector:
    app: go-service
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  type: ClusterIP

Apply the service manifest:

kubectl apply -f service.yaml