Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Start deprecating all generators in run except for run-pod/v1 #68132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2018

Conversation

soltysh
Copy link
Contributor

@soltysh soltysh commented Aug 31, 2018

What this PR does / why we need it:
This was discussed during SIG-CLI meetings over several past months. The direction is that we want to move away from kubectl run because it's over bloated and complicated for both users and developers. We want to mimic docker run with kubectl run so that it only creates a pod, and if you're interested in other resources kubectl create is the intended replacement.

This PR starts with deprecating all of the generator except for the pod one.

/assign @juanvallejo
/sig cli
/milestone v1.12

Release note:

Deprecate kubectl run generators, except for run-pod/v1

@soltysh soltysh added this to the v1.12 milestone Aug 31, 2018
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. sig/cli Categorizes an issue or PR as relevant to SIG CLI. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. area/kubectl approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 31, 2018
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Sep 4, 2018
@juanvallejo
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 4, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: juanvallejo, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 63011, 68089, 67944, 68132). If you want to cherry-pick this change to another branch, please follow the instructions here: https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md.

@brendandburns
Copy link
Contributor

brendandburns commented Oct 20, 2018

@soltysh can we get some clarification here, it seems that 'kubectl run ' will remain, but the deprecation warning for 'kubectl run' seems to indicate that it's all going to be deprecated.

I think that this is because the default for kubectl run is Deployment based, not run-pod, but I think that is leading to some confusion (e.g. https://stackoverflow.com/questions/52890718/kubectl-run-is-deprecated-looking-for-alternative)

I think we should make it clear that a user can run:

kubectl run --generator=run-pod/v1 ... to get the behavior they likely want rather than looking for a new command.

@soltysh
Copy link
Contributor Author

soltysh commented Oct 26, 2018

@brendandburns the main gist is, we want the kubectl run to mimic docker run in k8s world. For creating resources we already have a bunch of kubectl create sub-commands. Additionally, the vast majority of different options and their influence on the actual resource produces by kubectl run is another reason we're going into simple and straightforward direction. I've replied in the SO thread. I'll also post that on my personal twitter, appreciate retweets for greater audience.

@soltysh
Copy link
Contributor Author

soltysh commented Oct 26, 2018

I've also opened #70288 to improve the deprecation warning.

@mbigras
Copy link

mbigras commented May 1, 2021

This change breaks the example in the most recent Kubernetes Up & Running in the Service Discovery section. The following command is used:

$ kubectl run alpaca-prod \
 --image=gcr.io/kuar-demo/kuard-amd64:blue \
 --replicas=3 \
 --port=8080 \
 --labels="ver=1,app=alpaca,env=prod"

Using the --generator=run-pod/v1 flag idea like @brendanburns suggested doesn't work either:

$ kubectl run alpaca-prod --generator=run-pod/v1 --image=gcr.io/kuar-demo/kuard-amd64:blue --port=8080 --labels="app=foo,ver=1,env=prod" --replicas=3
Flag --generator has been deprecated, has no effect and will be removed in the future.
Flag --replicas has been deprecated, has no effect and will be removed in the future.
pod/foo-prod created

To continue along with the Kubernetes Up & Running example use this procedure:

  1. Delete the alpaca-prod pod

    kubectl delete pod alpaca-prod
    
  2. Read a blog post learn about the situation

  3. Use this bash heredoc

    some_yaml=$(mktemp)
    cat <<EOF > $some_yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: alpaca-prod
      labels:
        app: alpaca
        ver: 1
        env: prod
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: alpaca
      template:
        metadata:
          labels:
            app: alpaca
        spec:
          containers:
          - name: alpaca-prod
            image: gcr.io/kuar-demo/kuard-amd64:blue
            ports:
            - containerPort: 8080
    EOF
    kubectl apply -f $some_yaml
    error: unable to decode "/var/folders/_r/52tr69g54qvbxtg8fx7548tm0000gq/T/tmp.L5mckdlN": resource.metadataOnlyObject.ObjectMeta: v1.ObjectMeta.Name: Labels: ReadString: expects " or n, but found 1, error found in #10 byte of ...|d","ver":1},"name":"|..., bigger context ...|ta":{"labels":{"app":"alpaca","env":"prod","ver":1},"name":"alpaca-prod"},"spec":{"replicas":3,"sele|...
    
  4. Install a command-line tool to check if the YAML is right

    brew install yj
    yj < $some_yaml
    {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"alpaca-prod","labels":{"app":"alpaca","ver":1,"env":"prod"}},"spec":{"replicas":3,"selector":{"matchLabels":{"app":"alpaca"}},"template":{"metadata":{"labels":{"app":"alpaca"}},"spec":{"containers":[{"name":"alpaca-prod","image":"gcr.io/kuar-demo/kuard-amd64:blue","ports":[{"containerPort":8080}]}]}}}}
    
  5. Read the error message more closely and then use this YAML instead

    some_yaml=$(mktemp)
    cat <<EOF > $some_yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
     name: alpaca-prod
     labels:
       app: alpaca
       ver: "1"
       env: prod
    spec:
     replicas: 3
     selector:
       matchLabels:
         app: alpaca
     template:
       metadata:
         labels:
           app: alpaca
       spec:
         containers:
         - name: alpaca-prod
           image: gcr.io/kuar-demo/kuard-amd64:blue
           ports:
           - containerPort: 8080
    EOF
    kubectl apply -f $some_yaml
    deployment.apps/alpaca-prod created
    
    • Labels need to be strings
  6. Expose the alpaca-prod service

    kubectl expose deployment alpaca-prod
    
  7. Continue with the Kubernetes Up & Running example

    kubectl expose deployment alpaca-prod
    kubectl get services -o wide
    ALPACA_POD=$(kubectl get pods -l app=alpaca \
     -o jsonpath='{.items[0].metadata.name}')
    kubectl port-forward $ALPACA_POD 48858:8080
    
  8. Connect to the app

    open http://localhost:48858
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants