2018-07-26 04:22:00 +00:00
|
|
|
# Copyright 2018 Google LLC
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
kubernetes: use apps/v1 for Deployment (#166)
In certain situations (see details below), the deployment to Kubernetes fails with:
> "The Deployment [DEPLOYMENT_OBJECT] is invalid: [...] `selector` does not match template `labels`".
This is caused by the K8S Deployment manifests missing an explicit `selector` value.
This commit:
* adds explicit `selector` values for all Deployment objects.
* bumps the K8S API from the deprecated `extensions/v1beta1` version to the stable `apps/v1` version. This version made the `selector` property of the Deployment a required value, preventing any issues with missing selectors in the future.
This change is backwards compatible with existing deployments of the microservices demo app. I.e. you should be able to pull this change and run `skaffold run` against an existing deployment of the app without issues.
This will not however resolve the issue for existing deployments. Selectors are immutable and will therefore retain their current defaulted value. You should run `skaffold delete` followed by `skaffold run` after having pulled this change to do a clean re-deployment of the app, which will resolve the issue.
**The nitty-gritty details**
In the `extensions/v1beta1` version of K8S API (the version that was used by this project), the `selector` property of a Deployment object is optional and is defaulted to the labels used in the pod template. This can cause subtle issues leading to deployment failures. This project, where Deployment selectors were omitted, is a good example of what can go wrong with defaulted selectors.
Consider this:
1. Run `skaffold run` to build locally with Docker and deploy.
Since the Deployment specs don't have explict selectors, they will be defaulted to the pod template labels. And since skaffold adds additional labels to the pod template like `skaffold-builder` and `skaffold-deployer`, the end-result will be a selector that looks like this:
> app=cartservice,cleanup=true,docker-api-version=1.39,skaffold-builder=local,skaffold-deployer=kubectl,skaffold-tag-policy=git-commit,tail=true
So far, so good.
2. Now run `skaffold run -p gcb --default-repo=your-gcr-repo` to build on Google Cloud Build instead of building locally.
This will blow up when attempting to deploy to Kubernetes with an error similar to:
> The Deployment "cartservice" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"skaffold-builder":"google-cloud-build", "profiles"="gcb", "skaffold-deployer":"kubectl", "skaffold-tag-policy":"git-commit", "docker-api-version":"1.39", "tail":"true", "app":"cartservice", "cleanup":"true"}: `selector` does not match template `labels`
(and the same error for every other deployment object)
This is because the skaffold labels that were automatically added to the pod template have changed to include references to Google Cloud Build. That normally shouldn't be an issue.
But without explicit Deployment selectors, this results in the defaulted selectors for our Deployment objects to have also changed. Which means that the new version of our Deployment objects are now managing different sets of Pods. Which is thankfully caught by kubectl before the deployment happens (otherwise this would have resulted in orphaned pods).
In this commit, we explicitely set the `selector` value of all Deployment objects, which fixes this issue. We also bump the K8S API version to the stable `apps/v1`, which makes the `selector` property a required value and will avoid accidently forgetting selectors in the future.
More details if you're curious:
* Why defaulted Deployment selectors cause problems: https://github.com/kubernetes/kubernetes/issues/26202
* Why Deployment selectors should be (and were made) immutable: https://github.com/kubernetes/kubernetes/issues/50808
2019-03-04 18:52:55 +00:00
|
|
|
apiVersion: apps/v1
|
2018-06-28 23:53:56 +00:00
|
|
|
kind: Deployment
|
|
|
|
metadata:
|
|
|
|
name: frontend
|
|
|
|
spec:
|
kubernetes: use apps/v1 for Deployment (#166)
In certain situations (see details below), the deployment to Kubernetes fails with:
> "The Deployment [DEPLOYMENT_OBJECT] is invalid: [...] `selector` does not match template `labels`".
This is caused by the K8S Deployment manifests missing an explicit `selector` value.
This commit:
* adds explicit `selector` values for all Deployment objects.
* bumps the K8S API from the deprecated `extensions/v1beta1` version to the stable `apps/v1` version. This version made the `selector` property of the Deployment a required value, preventing any issues with missing selectors in the future.
This change is backwards compatible with existing deployments of the microservices demo app. I.e. you should be able to pull this change and run `skaffold run` against an existing deployment of the app without issues.
This will not however resolve the issue for existing deployments. Selectors are immutable and will therefore retain their current defaulted value. You should run `skaffold delete` followed by `skaffold run` after having pulled this change to do a clean re-deployment of the app, which will resolve the issue.
**The nitty-gritty details**
In the `extensions/v1beta1` version of K8S API (the version that was used by this project), the `selector` property of a Deployment object is optional and is defaulted to the labels used in the pod template. This can cause subtle issues leading to deployment failures. This project, where Deployment selectors were omitted, is a good example of what can go wrong with defaulted selectors.
Consider this:
1. Run `skaffold run` to build locally with Docker and deploy.
Since the Deployment specs don't have explict selectors, they will be defaulted to the pod template labels. And since skaffold adds additional labels to the pod template like `skaffold-builder` and `skaffold-deployer`, the end-result will be a selector that looks like this:
> app=cartservice,cleanup=true,docker-api-version=1.39,skaffold-builder=local,skaffold-deployer=kubectl,skaffold-tag-policy=git-commit,tail=true
So far, so good.
2. Now run `skaffold run -p gcb --default-repo=your-gcr-repo` to build on Google Cloud Build instead of building locally.
This will blow up when attempting to deploy to Kubernetes with an error similar to:
> The Deployment "cartservice" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"skaffold-builder":"google-cloud-build", "profiles"="gcb", "skaffold-deployer":"kubectl", "skaffold-tag-policy":"git-commit", "docker-api-version":"1.39", "tail":"true", "app":"cartservice", "cleanup":"true"}: `selector` does not match template `labels`
(and the same error for every other deployment object)
This is because the skaffold labels that were automatically added to the pod template have changed to include references to Google Cloud Build. That normally shouldn't be an issue.
But without explicit Deployment selectors, this results in the defaulted selectors for our Deployment objects to have also changed. Which means that the new version of our Deployment objects are now managing different sets of Pods. Which is thankfully caught by kubectl before the deployment happens (otherwise this would have resulted in orphaned pods).
In this commit, we explicitely set the `selector` value of all Deployment objects, which fixes this issue. We also bump the K8S API version to the stable `apps/v1`, which makes the `selector` property a required value and will avoid accidently forgetting selectors in the future.
More details if you're curious:
* Why defaulted Deployment selectors cause problems: https://github.com/kubernetes/kubernetes/issues/26202
* Why Deployment selectors should be (and were made) immutable: https://github.com/kubernetes/kubernetes/issues/50808
2019-03-04 18:52:55 +00:00
|
|
|
selector:
|
|
|
|
matchLabels:
|
|
|
|
app: frontend
|
2018-06-28 23:53:56 +00:00
|
|
|
template:
|
|
|
|
metadata:
|
|
|
|
labels:
|
|
|
|
app: frontend
|
2019-12-16 14:30:23 +00:00
|
|
|
annotations:
|
|
|
|
sidecar.istio.io/rewriteAppHTTPProbers: "true"
|
2018-06-28 23:53:56 +00:00
|
|
|
spec:
|
|
|
|
containers:
|
|
|
|
- name: server
|
2018-12-03 22:19:12 +00:00
|
|
|
image: frontend
|
2018-06-28 23:53:56 +00:00
|
|
|
ports:
|
|
|
|
- containerPort: 8080
|
2018-06-29 01:15:05 +00:00
|
|
|
readinessProbe:
|
|
|
|
initialDelaySeconds: 10
|
|
|
|
httpGet:
|
2018-09-05 05:42:46 +00:00
|
|
|
path: "/_healthz"
|
2018-06-29 01:15:05 +00:00
|
|
|
port: 8080
|
2018-06-29 01:34:48 +00:00
|
|
|
httpHeaders:
|
|
|
|
- name: "Cookie"
|
|
|
|
value: "shop_session-id=x-readiness-probe"
|
2018-06-29 01:15:05 +00:00
|
|
|
livenessProbe:
|
|
|
|
initialDelaySeconds: 10
|
|
|
|
httpGet:
|
2018-10-02 06:20:42 +00:00
|
|
|
path: "/_healthz"
|
2018-06-29 01:15:05 +00:00
|
|
|
port: 8080
|
2018-06-29 01:34:48 +00:00
|
|
|
httpHeaders:
|
|
|
|
- name: "Cookie"
|
|
|
|
value: "shop_session-id=x-liveness-probe"
|
2018-06-28 23:53:56 +00:00
|
|
|
env:
|
2019-05-09 02:39:14 +00:00
|
|
|
- name: PORT
|
|
|
|
value: "8080"
|
2018-06-28 23:53:56 +00:00
|
|
|
- name: PRODUCT_CATALOG_SERVICE_ADDR
|
|
|
|
value: "productcatalogservice:3550"
|
|
|
|
- name: CURRENCY_SERVICE_ADDR
|
|
|
|
value: "currencyservice:7000"
|
|
|
|
- name: CART_SERVICE_ADDR
|
|
|
|
value: "cartservice:7070"
|
|
|
|
- name: RECOMMENDATION_SERVICE_ADDR
|
|
|
|
value: "recommendationservice:8080"
|
|
|
|
- name: SHIPPING_SERVICE_ADDR
|
|
|
|
value: "shippingservice:50051"
|
|
|
|
- name: CHECKOUT_SERVICE_ADDR
|
|
|
|
value: "checkoutservice:5050"
|
2018-08-17 01:01:03 +00:00
|
|
|
- name: AD_SERVICE_ADDR
|
|
|
|
value: "adservice:9555"
|
2020-04-23 21:12:30 +00:00
|
|
|
- name: ENV_PLATFORM
|
|
|
|
value: "gcp"
|
2020-02-20 20:26:44 +00:00
|
|
|
# - name: DISABLE_TRACING
|
|
|
|
# value: "1"
|
|
|
|
# - name: DISABLE_PROFILER
|
|
|
|
# value: "1"
|
2019-01-08 19:08:20 +00:00
|
|
|
# - name: JAEGER_SERVICE_ADDR
|
|
|
|
# value: "jaeger-collector:14268"
|
2018-06-28 23:53:56 +00:00
|
|
|
resources:
|
|
|
|
requests:
|
|
|
|
cpu: 100m
|
|
|
|
memory: 64Mi
|
|
|
|
limits:
|
|
|
|
cpu: 200m
|
|
|
|
memory: 128Mi
|
|
|
|
---
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Service
|
|
|
|
metadata:
|
|
|
|
name: frontend
|
|
|
|
spec:
|
|
|
|
type: ClusterIP
|
|
|
|
selector:
|
|
|
|
app: frontend
|
|
|
|
ports:
|
2018-07-08 00:14:52 +00:00
|
|
|
- name: http
|
|
|
|
port: 80
|
2018-06-28 23:53:56 +00:00
|
|
|
targetPort: 8080
|
|
|
|
---
|
|
|
|
apiVersion: v1
|
|
|
|
kind: Service
|
|
|
|
metadata:
|
|
|
|
name: frontend-external
|
|
|
|
spec:
|
|
|
|
type: LoadBalancer
|
|
|
|
selector:
|
|
|
|
app: frontend
|
|
|
|
ports:
|
2018-07-19 16:53:28 +00:00
|
|
|
- name: http
|
|
|
|
port: 80
|
2018-06-28 23:53:56 +00:00
|
|
|
targetPort: 8080
|