0

I’m new to Kubernetes and learning about Deployments, Services, and Ingress as part of a CKAD video course. I created a YAML file for a Deployment, and a separate YAML file for a Service, and I’d like to map or hook up the Service with the Deployment. The container is a simple Nginx image, and I would like to be able to access the the Nginx server from the internal cluster IP address to begin with.

The deployment:

user@k8s-box:~/ch8$ cat ch8_deploy.yml apiVersion: apps/v1 kind: Deployment metadata: creationTimestamp: null labels: app: ch8app name: ch8app-nginx spec: replicas: 5 selector: matchLabels: app: ch8app strategy: rollingUpdate: maxUnavailable: 2 template: metadata: creationTimestamp: null labels: app: ch8app spec: containers: - image: nginx:latest name: nginx resources: {} status: {} 

The ClusterIP service:

user@k8s-box:~/ch8$ cat ch8_svc.yml apiVersion: v1 kind: Service metadata: creationTimestamp: null labels: app: ch8app name: ch8svc spec: ports: - name: "tcp80" port: 80 protocol: TCP targetPort: 80 selector: app: ch8app-nginx type: ClusterIP status: loadBalancer: {} 

Then I load the files:

kubectl create -f ch8_deploy.yml kubectl create -f ch8_svc.yml 

When I try to access port 80 with curl from the cluster internal IP address, I’m not able to connect. What am I missing in the above that is causing the mismatch? If I run the below, I’m able to connect successfully:

kubectl create -f ch8_deploy.yml kubectl expose deploy ch8app-nginx —-port=80 

While the above works, it’s not something like the YAML file that I could commit to a git repo for reproducing the environment.

1 Answer 1

0

In the service you have selector app: ch8app-nginx, but in the deployment you have labels app: ch8app. They don't match.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.