我正在尝试使用 python 脚本执行kubectl命令,但不断收到错误。我需要执行kubectl命令来创建 pod 并检查pod日志是否有任何失败。
我在这里做错了什么?
import subprocess
command = 'kubectl apply -f deployment.yaml'
check_output= subprocess.check_output(command)
print(check_output)
Run Code Online (Sandbox Code Playgroud)
错误
Traceback (most recent call last):
File "/usr/bin/cma-scripts/kubectl.py", line 6, in <module>
check_output= subprocess.check_output(command)
File "/usr/local/lib/python3.9/subprocess.py", line 424, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/local/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/local/lib/python3.9/subprocess.py", line 1821, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: …Run Code Online (Sandbox Code Playgroud) 使用nginx-ingress,是否可以仅对给定路径启用基本身份验证(或对所有路径启用基本身份验证并从中排除某些路径)?
该文档仅显示如何保护所有路径。
我在 digitalocean 上创建了 kubernetes 集群。我已经在 kubernetes 集群上部署了 k6 作为作业。
apiVersion: batch/v1
kind: Job
metadata:
name: benchmark
spec:
template:
spec:
containers:
- name: benchmark
image: loadimpact/k6:0.29.0
command: ["k6", "run", "--vus", "2", "--duration", "5m", "--out", "json=./test.json", "/etc/k6-config/script.js"]
volumeMounts:
- name: config-volume
mountPath: /etc/k6-config
restartPolicy: Never
volumes:
- name: config-volume
configMap:
name: k6-config
Run Code Online (Sandbox Code Playgroud)
这就是我的 k6-job.yaml 文件的样子。在 kubernetes 集群中部署它后,我检查了 pods 日志。它显示权限被拒绝错误。level=error msg="open ./test.json: permission denied" 如何解决这个问题?
我正在一个小型 Kubernetes 集群上测试 Calico 项目,并尝试找出“全局策略”和“网络策略”之间的哪一个将首先应用于数据流。
我的理解是:
我做了很多测试,但有时全局网络策略优先于网络策略,有时恰恰相反。
你能解释一下并告诉我是否有什么地方错了吗?
谢谢你!
我想启动一个容器并直接redis-cli在里面交互运行。由于某种原因,在我的尝试中,输入总是被忽略。
启动交互式 shell,然后手动启动程序即可:
# in my local shell:
$ kubectl run redis-cli --image redis:latest --attach --leave-stdin-open --rm -it --command -- bash
# then in container shell:
root@redis-cli:/data# redis-cli -h redis.example.com
# now the redis-cli shell is open:
redis.example.com:6379>
Run Code Online (Sandbox Code Playgroud)
如何将其合并到一个命令中以直接进入redis-clishell?我已尝试以下操作,但没有看到任何提示,并且我的所有输入都被忽略。我什至无法按 ctrl-C 或 ctrl-D 退出它。
# in my local shell:
$ kubectl run redis-cli --image redis:latest --attach --leave-stdin-open --rm -it --command -- bash
# then in container shell:
root@redis-cli:/data# redis-cli -h redis.example.com
# now the redis-cli shell is …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Cert-Manager 在我的 AKS 群集中添加自签名证书。
我ClusterIssuer为 CA 证书创建了一个(用于签署证书),ClusterIssuer为我要使用的证书(自签名)创建了第二个。
我不确定certificate2Ingress 是否正确使用它,因为它看起来正在等待某个事件。
我是否遵循正确的方法来执行此操作?
这是第一个ClusterIssuer“clusterissuer.yml”:
apiVersion: cert-manager.io/v1alpha2
kind: ClusterIssuer
metadata:
name: selfsigned
spec:
selfSigned: {}
Run Code Online (Sandbox Code Playgroud)
这是 CA 证书“certificate.yml”:
apiVersion: cert-manager.io/v1alpha2
kind: Certificate
metadata:
name: selfsigned-certificate
spec:
secretName: hello-deployment-tls-ca-key-pair
dnsNames:
- "*.default.svc.cluster.local"
- "*.default.com"
isCA: true
issuerRef:
name: selfsigned
kind: ClusterIssuer
Run Code Online (Sandbox Code Playgroud)
ClusterIssuer这是我要使用的证书的第二个“clusterissuer2.yml”:
apiVersion: cert-manager.io/v1alpha2
kind: ClusterIssuer
metadata:
name: hello-deployment-tls
spec:
ca:
secretName: hello-deployment-tls-ca-key-pair
Run Code Online (Sandbox Code Playgroud)
最后这是自签名证书“certificate2.yml”:
apiVersion: cert-manager.io/v1alpha2
kind: Certificate
metadata:
name: selfsigned-certificate2
spec:
secretName: hello-deployment-tls-ca-key-pair2
dnsNames: …Run Code Online (Sandbox Code Playgroud) ssl-certificate kubernetes kubernetes-ingress azure-aks cert-manager
和:
kubectl apply -f web.yaml --server-dry-run --validate=false -o yaml
我收到错误:
Error: unknown flag: --server-dry-run
See 'kubectl apply --help' for usage.
Run Code Online (Sandbox Code Playgroud)
甚至还有:
kubectl apply -f web.yaml --dry-run=server --validate=false -o yaml
我收到另一个错误:
Warning: resource deployments/web is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
Error from server (Conflict): error when applying patch:
{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"annotations\":{},\"creationTimestamp\":\"2021-12-30T08:51:06Z\",\"generation\":1,\"labels\":{\"app\":\"web\"},\"name\":\"web\",\"namespace\":\"default\",\"resourceVersion\":\"1589\",\"uid\":\"c2a4c20e-f55b-4113-b8e6-d2c19bb3e91c\"},\"spec\":{\"progressDeadlineSeconds\":600,\"replicas\":1,\"revisionHistoryLimit\":10,\"selector\":{\"matchLabels\":{\"app\":\"web\"}},\"strategy\":{\"rollingUpdate\":{\"maxSurge\":\"25%\",\"maxUnavailable\":\"25%\"},\"type\":\"RollingUpdate\"},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"app\":\"web\"}},\"spec\":{\"containers\":[{\"image\":\"nginx\",\"imagePullPolicy\":\"Always\",\"name\":\"nginx\",\"resources\":{},\"terminationMessagePath\":\"/dev/termination-log\",\"terminationMessagePolicy\":\"File\"}],\"dnsPolicy\":\"ClusterFirst\",\"restartPolicy\":\"Always\",\"schedulerName\":\"default-scheduler\",\"securityContext\":{},\"terminationGracePeriodSeconds\":30}}},\"status\":{}}\n"},"resourceVersion":"1589"}}
to:
Resource: …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习 Kubernetes。我不明白的一件事是以下场景:
鉴于我有一个带有 2 个容器的 Pod。一个容器运行一个侦听端口 80 的应用程序,另一个容器是一个 sidecar,它从 Web 资源进行一些轮询,但不侦听任何端口。
现在,当我使用 = 80 启动服务时TargetPort,Kubernetes 如何知道 pod 中的哪个容器公开此端口?它是否检查所有容器以检查暴露的端口?或者它只是在Pod 内的所有容器上对端口 80 进行映射?
此外,是否可以更改 Kubernetes 中容器公开的端口,以便容器公开的端口 (= ) 映射到容器内的containerPort不同端口?我的意思是类似Docker 中的-p参数。
我已经从 gitlab 官方 helm 图表部署了 Gitlab。当我部署它时,我没有启用 LDAP。请注意,我没有编辑values.yaml,而是使用helm update --install XXX命令来完成此操作。
我的问题是如何提取现有 Helm 部署(名称:)的 Helm Values.yaml prime-gitlab。我知道如何使用helm value show命令从 gitlab/artifactoryhub 下载 value.yaml,但在这里我想提取现有的 value.yaml,以便我可以编辑 value.yaml 文件中的 LDAP 部分。
01:36 AM \xe2\x9c\x94 root on my-k8s-man-01 \xce\x94 [~] \xce\xa9 helm ls -n prime-gitlab\nNAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION\nprime-gitlab prime-gitlab 1 2022-02-12 01:02:15.901215658 -0800 PST deployed gitlab-5.7.2 14.7.2\nRun Code Online (Sandbox Code Playgroud)\n 当我们的容器注册表和整个 K8S 集群都断电时,我们发生了一次严重的中断。当集群恢复速度快于容器注册表时,我的 pod(有状态集的一部分)陷入困境 Error: ImagePullBackOff。
是否有配置设置可以定期重试从 CR 下载映像或在无需手动干预的情况下恢复?
我查看了imagePullPolicy,但这不适用于 CR 不可用的情况。
kubernetes ×9
kubectl ×3
azure-aks ×1
calico ×1
cert-manager ×1
containers ×1
k6 ×1
ldap ×1
python ×1
python-3.x ×1
redis ×1
redis-cli ×1
subprocess ×1
yaml ×1