使用 shell 脚本更新 kube 上下文

时间:2021-07-08 22:51:14

标签: amazon-web-services shell kubernetes amazon-eks

我正在尝试使用 shell 脚本设置集群的当前上下文。

class EditItemForm(forms.ModelForm):

    name = forms.CharField( max_length=80, min_length=3, required=True )
    
    def clean_name(self):
        # Get the name
        name = self.cleaned_data.get('name')
    
        if Item.objects.filter(name=name).exclude(id=id).exists(): 
            raise forms.ValidationError('This name is already in use.')
    
    class Meta:
        model = Item
        fields = ('type', 'name',  )



class Item(models.Model):

    type = models.IntegerField(choices=TYPE, blank=False, default=NO_CAT)
    name = models.CharField(max_length=250 )
    
    def __str__(self):  #metodo righiesto
        return self.name

然而,上面的命令报错:

<块引用>

sh: 0: 无法打开 aws eks update-kubeconfig --name abc-eks-cluster --role-arn arn:aws:iam::43999999999873:role/abc-eks-cluster-cluster-admin - -别名 abc-eks-cluster

有人可以建议我如何解决问题以及如何设置当前上下文,因为 k8_host 命令产生了另一个未设置上下文的错误。

1 个答案:

答案 0 :(得分:2)

我不知道为什么你甚至将 sh 作为子 shell,当你已经在一个 shell 脚本中时,但是

<块引用>

有人可以建议我吗...有什么问题

您已向 sh 提供了整个命令,但未能使用 -c 通知它第一个参数是内联 shell 片段;否则,sh 期望第一个非选项参数是一个 file 这就是为什么它说它不能打开一个名字那么长的文件

摆脱这种混乱有两种结果:使用 -c 或停止尝试使用 subshel​​l

  sh -c "aws eks update-kubeconfig --name abc-eks-cluster --role-arn ${cluster_arn} --alias abc-eks-cluster"

或:

aws eks update-kubeconfig --name abc-eks-cluster --role-arn ${cluster_arn} --alias abc-eks-cluster
相关问题