是否可以在没有负载均衡器的情况下在 Kubernetes 中使用 Ingress Controller 功能(在 Digital Ocean 中)。
是否有其他机制可以让域名映射到 Kubernetes 服务;例如,如果我在 Kubernetes 集群上托管两个 WordPress 站点:
==> WP 站点 1:节点端口 80 ==> WP 站点 2:节点端口 8080
域名如何映射到容器端口 8080 而不显式输入端口号。
任何帮助表示赞赏。
我正在尝试创建和安装卷,但卡住了。
这部分创建存储:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvclaim2
spec:
accessModes:
- ReadWriteOnce
storageClassName: managed-premium
resources:
requests:
storage: 5Gi
Run Code Online (Sandbox Code Playgroud)
以下是我的部署部分的延续:
volumeMounts:
- name: config
mountPath: /config
readOnly: true
args:
- --configfile=/config/traefik.toml
volumes:
- name: config
persistentVolumeClaim:
claimName: pvclaim2
configMap:
name: traefik-config
Run Code Online (Sandbox Code Playgroud)
我不断收到以下错误消息:
部署“traefik-ingress-controller”无效:spec.template.spec.containers[0].volumeMounts[0].name:未找到:“config”
任何帮助表示赞赏。
更新:
Output from describe pv:
Conditions:
Type Status
PodScheduled False
Volumes:
certs:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: pvclaim101
ReadOnly: false
config:
Type: ConfigMap (a volume populated by a ConfigMap) …Run Code Online (Sandbox Code Playgroud) 我有一个 Kubernetes 集群,各种资源运行良好。我试图让仪表板正常工作,但在启动仪表板并输入服务帐户令牌时出现以下错误。
permanentvolumeclaims 被禁止:用户“system:serviceaccount:kube-system:kubernetes-dashboard”无法在命名空间“default”中的 API 组“”中列出资源“persistentvolumeclaims”
它不允许列出我的集群中的任何资源(持久卷、pod、入口等)。我的集群有多个命名空间。
这是我的服务帐户 yaml 文件:
apiVersion: v1
kind: ServiceAccount
metadata:
name: k8s-test # replace with your preferred username
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: dashboard-admin # replace with your preferred username
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: dashboard-admin # replace with your preferred username
namespace: kube-system
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。
我正在尝试使用 traefik 获取 Kubernetes pod 的真实源 IP 地址。我正在使用启用了代理协议的数字海洋负载均衡器。我还配置了 K8s 服务 yaml,将外部流量策略设置为本地。
从我的 K8s 中的 Traefik Ingress configmap 中摘录。我已经编辑了我的实际 IP,但我使用我的负载均衡器 IP 和 Kubernetes 工作节点专用 IP
[entryPoints]
[entryPoints.http]
address = ":80"
compress = true
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
compress = true
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
CertFile = "/ssl/client_co.crt"
KeyFile = "/ssl/tls.key"
[entryPoints.https.proxyProtocol]
trustedIPs = ["Load Balancer IP, Kubernetes Worker Node IPs"]
[entryPoints.https.redirect]
regex = "^https://(?:www\\.)(.*)"
replacement = "https://$1"
permanent = true
Run Code Online (Sandbox Code Playgroud)
这是部署文件服务yaml的一部分
kind: Service
apiVersion: v1
metadata:
name: traefik-ingress-service …Run Code Online (Sandbox Code Playgroud) 我有一个利用多个容器的Web应用程序(基于Django):
根据我阅读的一些文档,我应该使用NGINX之类的东西来提供我的静态内容。但是我不知道该怎么做。我应该在Web应用程序容器上还是作为单独的NGINX容器安装NGINX。我如何通过Traefik的请求?据我所知,您无法使用Traefik服务器静态内容。
这是我的docker-compose.yml的样子:
traefik:
image: traefik
ports:
- 80:80
- 8080:8080
- 443:443
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./traefik/traefik.toml:/etc/traefik/traefik.toml:ro
- ./traefik/acme:/etc/traefik/acme
web:
build: .
restart: always
depends_on:
- db
- redis
- traefik
command: python3 /var/www/html/applications/py-saleor/manage.py makemigrations --noinput
command: python3 /var/www/html/applications/py-saleor/manage.py migrate --noinput
command: python3 /var/www/html/applications/py-saleor/manage.py collectstatic --noinput
command: bash -c "cd /var/www/html/applications/py-saleor/ && gunicorn saleor.wsgi -w 2 -b 0.0.0.0:8000"
volumes:
- .:/app
ports:
- 127.0.0.1:8000:8000
labels:
- "traefik.enable=true"
- "traefik.backend=web"
- "traefik.frontend.rule=${TRAEFIK_FRONTEND_RULE}"
environment:
- …Run Code Online (Sandbox Code Playgroud) 有人知道如何将列表传递给环境变量吗?目前我正在尝试将代码列表放入我的 settings.py 文件中。
我的 .env 文件中有这个:
ALLOWED_CODES='AB01', 'AB02'
Run Code Online (Sandbox Code Playgroud)
在我的 settings.py 这就是我所拥有的:
ALLOWED_CODES = [os.environ.get('ALLOWED_POSTCODES')]
Run Code Online (Sandbox Code Playgroud)
如果运行 docker-compose config 它被解析为:
ALLOWED_CODES: '''AB01'', ''AB02'''
Run Code Online (Sandbox Code Playgroud)
我想要的是它返回 .env 文件中定义的确切列表。
我有一个 Kubernetes 集群,其中部署了一些 pod(DB、前端、Redis)。我无法完全掌握的部分是删除 pod 后 PVC 会发生什么。
例如,如果我删除绑定到 CLAIM_A 的 POD_A,我知道 CLAIM_A 不会自动删除。如果我然后尝试重新创建 POD,它会附加回同一个 PVC,但所有数据都丢失了。
任何人都可以解释发生了什么,我已经查看了官方文档,但目前没有任何意义。
任何帮助表示赞赏。
kubernetes persistent-volumes persistent-volume-claims kubernetes-pod
我有一个 Django 视图,它有一些逻辑可以将正确的类别传递给模板。
class ProductListView(ListView):
model = models.Product
template_name = "catalogue/catalogue.html"
def get_queryset(self):
category = self.kwargs.get("category")
if category:
queryset = Product.objects.filter(category__iexact=category)
else:
queryset = Product.objects.all()
return queryset
Run Code Online (Sandbox Code Playgroud)
我不知道如何将它传递给模板,我的模板代码如下:
{% for product in products %}
<tr>
<td><h5>{{ product.name }}</h5>
<p>Cooked with chicken and mutton cumin spices</p></td>
<td><p><strong>£ {{ product.price }}</strong></p></td>
<td class="options"><a href="#0"><i class="icon_plus_alt2"></i></a></td>
</tr>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
我很确定我的模板语法是错误的,但是如何将特定类别传递给模板?因此,如果我有一个名为“Mains”的类别,我如何将电源的所有产品传递给模板。
我已经设置了一个 K8s 集群并获得了我放置在 username/.kube 目录中的配置文件
默认情况下,我似乎无法练习如何将我的 Powershell Kubectl 链接到此配置文件。例如,如果我尝试运行以下命令,我将无法获得已设置的集群。
kubectl config get-contexts
Run Code Online (Sandbox Code Playgroud)
但是,如果我运行以下命令,我会得到当前节点的列表
kubectl --kubeconfig="cluster-kubeconfig.yaml" get nodes
Run Code Online (Sandbox Code Playgroud) 我有一个文本文件,其中包含以下内容:
Line 1
,
,
Line 2
,
Line 3
,
Line 4
Run Code Online (Sandbox Code Playgroud)
我想创建一个函数来删除行之间的空白(标有 ,用于说明)
到目前为止,我已经使用以下代码创建了一个函数,但是当我运行它时没有任何反应:
with open('path/to/file.txt', 'r') as f:
for line in f:
line = line.strip()
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。
在我的 Kubernetes 集群中,在我的数据库容器上,如果 pod 被删除,我的持久性存储(在 Digital Ocean 上动态配置)不会持久化存储。
我已将存储的回收策略从删除更改为保留,但这并没有什么区别。
这是 DB YAML 文件的副本:
apiVersion: v1
kind: Service
metadata:
name: db
namespace: hm-namespace01
app: app1
spec:
type: NodePort
ports:
- port: 5432
selector:
app: app1
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: hm-pv-claim
namespace: hm-namespace01
labels:
app: app1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: do-block-storage
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app1
namespace: hm-namespace01
labels:
app: app1
spec:
selector:
matchLabels:
app: app1
tier: backend
strategy:
type: Recreate …Run Code Online (Sandbox Code Playgroud) 我正在开发Django购物车应用程序。我有两种型号的购物车和物品。我正在尝试将数量添加到购物篮中时更新数量,但无法使视图正常工作。我在使item_obj分配工作时遇到问题-在这里我需要对模型管理器做任何事情吗?任何帮助都非常感谢。
型号
class Cart(models.Model):
user = models.ForeignKey(User, null=True, blank=True)
products = models.ManyToManyField(Product, blank=True)
total = models.DecimalField(default=0.00, max_digits=10, decimal_places=2)
updated = models.DateTimeField(auto_now=True)
timestamp = models.DateTimeField(auto_now_add=True)
objects = CartManager()
def __str__(self):
return str(self.id)
class Item(models.Model):
item = models.ForeignKey(Product, null=True)
cart = models.ForeignKey(Cart, null=True)
quantity = models.PositiveIntegerField()
Run Code Online (Sandbox Code Playgroud)
Views.py提取
def cart_update(request):
product_id = request.POST.get('product_id')
product_obj = Item.objects.get(id=product_id)
print(item_id)
item_obj = Item.objects.get(id=product_id)
cart_obj, new_obj = Cart.objects.new_or_get(request)
if item_obj in cart_obj.products.all():
cart_obj.products.add(product_obj)
item_obj.quantity += 1
item_obj.save()
else:
cart_obj.products.add(product_obj)
return redirect("cart:home")
EDIT
Run Code Online (Sandbox Code Playgroud)
Views.py更新(12/02/2018)
def cart_update(request):
# Based …Run Code Online (Sandbox Code Playgroud) kubernetes ×7
django ×4
python ×3
traefik ×2
azure-aks ×1
django-forms ×1
django-views ×1
docker ×1
gunicorn ×1
kubectl ×1
nginx ×1
python-3.x ×1
real-ip ×1