Menu

Post image 1
Post image 2
1 / 2
0

Getting Started with Kubernetes: Creating a Basic Service

DEV Community·Josef Polar·about 1 month ago
#9qlNlxtJ
Reading 0:00
15s threshold

Run an app in a container, then expose it so traffic could actually reach it. Two resources handle this: a Deployment and a Service . Step 1: Writing the Deployment apiVersion : apps/v1 kind : Deployment metadata : name : my-app spec : replicas : 2 selector : matchLabels : app : my-app template : metadata : labels : app : my-app spec : containers : - name : my-app image : echo-server:latest ports : - containerPort : 80 Enter fullscreen mode Exit fullscreen mode This tells Kubernetes to run 2 copies of echo-server and label them app: my-app . The label part matters — I'll need it in a second. Step 2: Writing the Service apiVersion : v1 kind : Service metadata : name : my-app-service spec : selector : app : my-app ports : - protocol : TCP port : 80 targetPort : 80 type : ClusterIP Enter fullscreen mode Exit fullscreen mode The selector matches the label I set in the Deployment. That's how Kubernetes knows which pods to send traffic to. Once I understood that connection, the rest started clicking.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More