7

I am using minikube to learn about docker, but I have come across a problem.

I am following along with the examples in Kubernetes in Action, and I am trying to get a pod that I have pulled from my docker hub account, but I cannot make this pod visible.

if I run

kubectl get pod

I can see that the pod is present.

NAME    READY   STATUS    RESTARTS   AGE
kubia   1/1     Running   1          6d22h

However when I do the first step to create a service

kubectl expose rc kubia --type=LoadBalancer --name kubia-http service "kubia-http" exposed

I am getting this error returned

Error from server (NotFound): replicationcontrollers "kubia" not found
Error from server (NotFound): replicationcontrollers "service" not found
Error from server (NotFound): replicationcontrollers "kubia-http" not found
Error from server (NotFound): replicationcontrollers "exposed" not found

Any ideas why I am getting this error and what I need to do to correct it?

I am using minikube v1.13.1 on mac Mojave (v10.14.6), and I can't upgrade because I am using a company supplied machine, and all updates are controlled by HQ.

2
  • I'd recommend creating a Service in YAML syntax, checking it in with your other deployment artifacts, and installing it using kubectl apply -f kubia-service.yml; avoid imperative commands like kubectl expose.
    – David Maze
    Commented Oct 11, 2020 at 18:07
  • (Is service "kubia-http" exposed supposed to be the output of the kubectl expose command in the tutorial you're reading? Does removing those words help?)
    – David Maze
    Commented Oct 11, 2020 at 18:07

3 Answers 3

15

In this book, used command is kubectl run kubia --image=luksa/kubia --port=8080 --generator=run/v1 which used to create ReplicationController back in the days when book was written however this object is currently depracated.

Now kubectl run command creates standalone pod without ReplicationController. So to expose it you should run:

kubectl expose pod kubia --type=LoadBalancer --name kubia-http

In order to create a replication it is recommended to use Deployment. To create it using CLI you can simply run

kubectl create deployment <name_of_deployment> --image=<image_to_be_used>

It will create a deployment and one pod. And then it can be exposed similarly to previous pod exposure:

kubectl expose deployment kubia --type=LoadBalancer --name kubia-http
3
  • 1
    This answer is not useful for someone who is reading Chapter 2, "First steps with Docker and Kubernetes," knows next to nothing about Kubernetes yet and is literally about to run their very first app on Kubernetes. Such a user doesn't know yet what a pod is, what it means to expose a pod, what a replication is or why you would want to create one, nor what a deployment is. To such a user it is unclear which of the above commands, or which subset of the above commands, should replace the command in the book. Commented Oct 20, 2021 at 23:47
  • @KevinS.VanHorn As one who is reading chapter 2, It's quite useful. Kool clearly states: "so to expose it you should run", while explaining that the book uses deprecated features.
    – Nexaspx
    Commented Jan 27, 2022 at 16:10
  • for anyone like me who is using minikube you may encounter that even after exposing your pod it is still inaccessible. the problem is that apparently minikube does not tunnel the traffic by default so your service can not resolve the EXTERNAL-IP address. you can verify that by running kubectl get services command. this problem can be resolved with command minikube tunnel. the original answer Commented Mar 15, 2023 at 11:31
0

Replication controllers are older concepts than creating services and deployments in Kubernetes, checkout this answer.

A service template looks like the following:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: App
  ports:
    - protocol: tcp
      port: 80
      targetPort: 8080

Then after saving the service config into a file you do kubectl apply -f <filename>

Checkout more at: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service

0

kubia.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubia
spec:
  replicas: 3
  selector:
    matchLabels:
      app: kubia
  template:
    metadata:
      labels:
        app: kubia
    spec:
      containers:
        - name: kubia
          image: seunggab/kubia:latest
          ports:
          - containerPort: 8080

shell

kubectl apply -f kubia.yaml
kubectl expose deployment kubia --type=LoadBalancer --port 8080 --name kubia-http

minikube tunnel &

curl 127.0.0.1:8080

if you change replicas

  1. change kubia.yaml (3 -> 5)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubia
spec:
  replicas: 5
  selector:
    matchLabels:
      app: kubia
  template:
    metadata:
      labels:
        app: kubia
    spec:
      containers:
        - name: kubia
          image: seunggab/kubia:latest
          ports:
          - containerPort: 8080
  1. re-apply
kubectl apply -f kubia.yaml

# as-is
NAME                     READY   STATUS    RESTARTS   AGE
kubia-5f896dc5d5-qp7wl   1/1     Running   0          20s
kubia-5f896dc5d5-rqqm5   1/1     Running   0          20s
kubia-5f896dc5d5-vqgj9   1/1     Running   0          20s

# to-be
NAME                     READY   STATUS              RESTARTS   AGE
kubia-5f896dc5d5-fsd49   0/1     ContainerCreating   0          6s
kubia-5f896dc5d5-qp7wl   1/1     Running             0          3m35s
kubia-5f896dc5d5-rqqm5   1/1     Running             0          3m35s
kubia-5f896dc5d5-vqgj9   1/1     Running             0          3m35s
kubia-5f896dc5d5-x84fr   1/1     Running             0          6s

Not the answer you're looking for? Browse other questions tagged or ask your own question.