4

I'm working through Kubernetes in Action (copyright 2018), and at least one of the examples is out-of-date with respect to current versions of kubectl.

Currently I'm stuck in section 2.3 on just trying to demo a simple web-server docker container ("kubia"):

kubectl run kubia --image=Dave/kubia --port=8080 --generator=run/v1

the --generator option has been removed from current versions of kubectl. What command(s) achieve the same end in the current version of kubectl?

Note: I'm literally just 2 chapters into learning about Kubernetes, so I don't really know what a deployment or anything else (so the official kubernetes docuementation doesn't help), I just need the simplest way to verify that that I can, in fact, run this container in my minikube "cluster".

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Dave
  • 7,555
  • 8
  • 46
  • 88
  • 1
    Does this answer your question? [kubectl run is deprecated - looking for alternative](https://stackoverflow.com/questions/52890718/kubectl-run-is-deprecated-looking-for-alternative) – moonkotte Mar 24 '22 at 10:10
  • @moonkotte no -- for someone at my limited level of understanding the answers there are incomprehensible. – Dave Mar 25 '22 at 20:24
  • I'm not sure how to formulate or tag this question to emphasize that I am very inexperienced with Kubernetes (literally 2 chapters in) and therefore require an answer that does not require more advanced understanding of this system. – Dave Mar 25 '22 at 20:40
  • Well, lack of knowledge/research is not a reason to tell someone that answer is not useful. You need to get more knowledge and everything will become clear. Two answers are provided and they answer on your question. Do you need anything else? Then edit your question to be more precise. – moonkotte Mar 28 '22 at 06:13

3 Answers3

1

in short , you can use following commands to create pods and deployments (imperative way) using following commands which are similar to the commands mentioned in that book :

  • To create a pod named kubia with image Dave/kubia
 kubectl run kubia --image=Dave/kubia --port=8080
  • To create a deployment named kubia with image Dave/kubia
kubectl create deployment kubia --image=Dave/kubia --port=8080
confused genius
  • 2,876
  • 2
  • 16
  • 29
  • What is the relationship between the deployment created by the second command and the replicationcontroller that is created by the command from the book? – Dave Mar 25 '22 at 21:10
  • @Dave Kubernetes recommends using create now to make it easier for new comers , so that the "run" command is only using for running a pod only and not to create deployments. – LumbusterTick Jul 02 '23 at 08:15
0

You can just instantiated the pod, since --generator has been deprecated.

apiVersion: v1
kind: Pod
metadata:
  name: kubia
spec:
  containers:
  - name: kubia
    image: Dave/kubia
    ports:
    - containerPort: 8080

Alternatively, you can use a deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubia-deployment
  labels:
    app: kubia
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kubia
  template:
    metadata:
      labels:
        app: kubia
    spec:
      containers:
      - name: kubia
        image: Dave/kubia
        ports:
        - containerPort: 8080

Save either one to a something.yaml file and run

kubectl create -f something.yaml

And to clean up

kubectl delete -f something.yaml

✌️

Rico
  • 58,485
  • 12
  • 111
  • 141
  • This answer assumes a level of familiarity with kubernetes that I do not (yet) have. – Dave Mar 25 '22 at 20:37
  • That's why they removed generator in the first place, they though that it wasn't something that would be used by people less familiar. I believe if you omit the generator option, a pod/deployment will still be created by default. – Rico Mar 25 '22 at 21:21
0

If someone who read same book (Kubernetes in Action, copyright 2018) have same issue in the future, just run pod instead of the replication controller and expose pod instead of rc in following chapter.

rema
  • 1