Kubernetes 1.18 كسر "kubectl run". ما ليحل محل؟

إذا كنت قد استخدمت الإصدارات السابقة من Kubernetes - نفس الإصدار 1.16 - فربما تكون قد رأيت تحذيرًا غريبًا من kubectl run.



حتى وقت قريب ، كان بإمكان هذا الأمر إنشاء كائنات للنشر أو YAML من سطر الأوامر. بدءًا من Kubernetes 1.18 ، تم كسر هذه الميزة بطريقة مفاجئة للغاية. المقالة سوف تجيب على أسئلة "لماذا؟" و "كيف نتعايش مع هذا أكثر؟"





قبل التعمق في هذه الأسئلة ، تذكر أن هناك ثلاث طرق رئيسية لإنشاء كائنات للنشر في Kubernetes:



  • من خلال واجهة برمجة التطبيقات (كما يفعل ، على سبيل المثال ، OpenFaaS)
  • عن طريق إنشاء ملف YAML يدويًا. أو أقرب إلى الواقع - انسخه والصقه من مكان ما من مواقع مختلفة (مرحبًا ، StackOverflow)
  • بإطلاق kubectl runأوkubectl run -o yaml --dry-run


كما ترى ، قمت أيضًا بإدراج الخيارات بترتيب التعقيد (من الصعب إلى البسيط).



قارن الخيارات



, API — , . API «extensions/v1beta», «apps/v1», YAML. , — Go YAML. Go IDE, , . Core? Meta? Apps? Extensions? , — Intellisense?





OpenFaaS Kubernetes (aka faas-netes)



— YAML . Twitter #kubernetes, , , , Kubernetes, , YAML.



, , , - , . , API Kubernetes.



apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-1
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80


Kubernetes, . , .



Kubernetes YAML , (, , . ).

:



  • ;
  • ;
  • YAML ;
  • CI\CD.


, , , :



$ kubectl run nginx-1 --image=nginx --port=80 --restart=Always


, — YAML , . , ?



$ kubectl run nginx-1 --image=nginx:1.14.2 --port=80 \
    --restart=Always -o yaml --dry-run
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: nginx-1
  name: nginx-1
spec:
  replicas: 1
  selector:
    matchLabels:
      run: nginx-1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: nginx-1
    spec:
      containers:
      - image: nginx:1.14.2
        name: nginx-1
        ports:
        - containerPort: 80
        resources: {}


, --replicas --serviceaccount. .



— , , Kubernetes 1.18 .





, , .



, : «, , »


$ kubectl run nginx-1 --image=nginx --port=80 --restart=Always
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/nginx-1 created


kubectl 1.17 ( 1.15 ), YAML. Kubernetes 1.18 :



kubectl run nginx-1 --image=nginx --port=80 --restart=Always -o yaml --dry-run
W0512 14:27:13.111424   30104 helpers.go:535] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx-1
  name: nginx-1
spec:
  containers:
  - image: nginx
    name: nginx-1
    ports:
    - containerPort: 80
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always


Pod — Deployment. service account , , , , , ( ) ip-. Deployments Services .



, curl api, Kafka.



inlets-operator, , .





helm chart, , . Deployment, LoadBalancer, VM , , ip-.



:



kubectl run nginx-1 --image=nginx --port=80 --restart=Always
kubectl expose deployment nginx-1 --port=80 --type=LoadBalancer


:



export DEPLOYMENT=nginx-1
(cat<<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: $DEPLOYMENT
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
EOF
) | kubectl apply -f -
kubectl expose deployment nginx-1 --port=80 --type=LoadBalancer


Kubernetes, kubectl expose ;-)

, Deployment. , , :



$ kubectl apply -f https://raw.githubusercontent.com/inlets/inlets-operator/master/contrib/nginx-sample-deployment.yaml


, kubectl apply -f .



?



, . , kubectl create deployment.



, , --port, --serviceaccount, --replicas --restart-policy.


kubectl create deployment --help
Create a deployment with the specified name.
Aliases:
deployment, deploy
Examples:
  # Create a new deployment named my-dep that runs the busybox image.
  kubectl create deployment my-dep --image=busybox
Options:
      --allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in
the template. Only applies to golang and jsonpath output formats.
      --dry-run='none': Must be "none", "server", or "client". If client strategy, only print the object that would be
sent, without sending it. If server strategy, submit server-side request without persisting the resource.
      --image=[]: Image name to run.
  -o, --output='': Output format. One of:
json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
      --save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the
annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
      --template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The
template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
      --validate=true: If true, use a schema to validate the input before sending it
Usage:
  kubectl create deployment NAME --image=image [--dry-run=server|client|none] [options]
Use "kubectl options" for a list of global command-line options (applies to all commands).


kubectl create, , YAML. — bash, .



— StackOverflow Kubernetes Deployment. ? YAML .



$ kubectl create deployment nginx-1 --image=nginx  -o yaml --dry-run
W0512 14:38:18.296270   30135 helpers.go:535] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx-1
  name: nginx-1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx-1
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}


, , restartPolicy .


?



, , , , .



Pull request 68132 , kubectl run docker run. .



, Kubernetes kubectl create deployment, , , : « — PR».





? Twitter, , .



- , , , Kubernetes, «». «».



1.18.



— , (Kubernetes, DevOps, Docker, Ansible, Ceph, SRE)




All Articles