Middle
What is needed to launch a service in Kubernetes?
sobes.tech AI
Answer from AI
To deploy a service in Kubernetes, you need to:
- Create a Docker image of your application.
- Write Kubernetes manifests — usually a Deployment to manage pods and a Service for access.
- Deploy the manifests to the cluster using
kubectl apply -f. - Check the status of pods and services with
kubectl get podsandkubectl get svc.
Example of a simple Deployment for a Go service:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-go-service
spec:
replicas: 3
selector:
matchLabels:
app: my-go-service
template:
metadata:
labels:
app: my-go-service
spec:
containers:
- name: my-go-service
image: myrepo/my-go-service:latest
ports:
- containerPort: 8080
And a Service for access:
apiVersion: v1
kind: Service
metadata:
name: my-go-service
spec:
selector:
app: my-go-service
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: ClusterIP
After this, the service will be accessible inside the cluster by the name my-go-service.