bright-horse-50102
04/22/2022, 3:44 AMconst labels = { appClass: 'app' };
export const appSvc = new k8s.core.v1.Service('app-svc', {
metadata: {
labels,
name: 'app-svc',
},
spec: {
type: 'ClusterIP',
clusterIP: 'None',
selector: labels,
},
}, {
provider,
});
export const interactionsApp = new k8s.apps.v1.StatefulSet('app', {
metadata: {
labels,
},
spec: {
serviceName: 'app-svc',
replicas: 3,
selector: {
matchLabels: labels,
},
template: {
metadata: {
labels,
},
spec: {
imagePullSecrets: [
{ name: registryCredentials.metadata.name },
],
containers: [
{ /* ... */ },
],
},
},
},
}, {
provider,
dependsOn: [
registryCredentials,
databaseUser,
redisInstance,
],
});
I hardcode the service's metadata.name
to 'app-svc'
and the statefulset's spec.serviceName
to 'app-svc'
as well. While this works, it feels wrong because now the resource name is not managed by pulumi.
If I don't specify metadata.name
in the service definition, and pass appSvc.metadata.name
to the statefulset spec.serviceName
, the statefulset is never created.. it waits for the appSvc
to become ready, but the appSvc
will never become ready because the statefulset hasn't been made yet:
kubernetes:core/v1:Service (app-svc):
error: 2 errors occurred:
* resource default/app-svc-4kc42v1c was successfully created, but the Kubernetes API server reported that it failed to fully initialize or become live: 'app-svc-4kc42v1c' timed out waiting to be Ready
* Service does not target any Pods. Selected Pods may not be ready, or field '.spec.selector' may not match labels on any Pods
how do I solve this issue? Is hardcoding the service name a good idea?little-cartoon-10569
04/22/2022, 3:54 AMbright-horse-50102
04/22/2022, 4:00 AMType Name Status Info
pulumi:pulumi:Stack _redacted_ **failed** 1 error
+ └─ kubernetes:core/v1:Service nginx-service **creating failed** 1 error
Diagnostics:
kubernetes:core/v1:Service (nginx-service):
error: 2 errors occurred:
* resource default/nginx-service-nm3byu6a was successfully created, but the Kubernetes API server reported that it failed to fully initialize or become live: 'nginx-service-nm3byu6a' timed out waiting to be Ready
* Service does not target any Pods. Selected Pods may not be ready, or field '.spec.selector' may not match labels on any Pods
pulumi:pulumi:Stack (_redacted_):
error: update failed
Is this the documentation being wrong or Pulumi being wrong?little-cartoon-10569
04/22/2022, 4:18 AMlabels
? You're specifying it as an object, but the examples all have it as an array of strings....bright-horse-50102
04/22/2022, 4:23 AMlabels
isn't a thing anymorelittle-cartoon-10569
04/22/2022, 4:24 AMbright-horse-50102
04/22/2022, 4:25 AMkubectl get statefulset
returns an empty list). I also don't see a creating...
in the pulumi cli output for the statefulset; it starts by trying to create the service first, it'll say the service is waiting for n
pods matching the selector, and this times out because those pods never get spawned (because the statefulset isn't being made)little-cartoon-10569
04/22/2022, 4:27 AMbright-horse-50102
04/22/2022, 4:27 AMbillowy-army-68599
bright-horse-50102
04/22/2022, 8:13 AMbillowy-army-68599
spec: {
selector: {
matchLabels: {
app: "nginx",
},
},
The reason you're having a hard time using serviceName: 'app-svc',
is because pulumi has logic in it to ensure the service has healthy pods behind it. by setting the name this way, you're creating a circular dependency. remove the serviceName
property and use the matchlabels property insteadbright-horse-50102
04/22/2022, 8:20 AMserviceName
anyway (right below the selector). It's included in the example. Am I missing something? 😅billowy-army-68599
bright-horse-50102
04/22/2022, 8:22 AM<http://k8s.gcr.io/nginx-slim:0.8|k8s.gcr.io/nginx-slim:0.8>
image. Copied the entire codeblock and didn't change anything elsebillowy-army-68599
bright-horse-50102
04/22/2022, 8:24 AMnginxService
to nginx-service
on line 4 because I was getting an error about service names having to be valid DNS names (i.e. lowercase). No changes other than thatimport * as kubernetes from '@pulumi/kubernetes';
const nginxService = new kubernetes.core.v1.Service('nginx-service', {
metadata: {
labels: {
app: 'nginx',
},
},
spec: {
ports: [ {
port: 80,
name: 'web',
} ],
clusterIP: 'None',
selector: {
app: 'nginx',
},
},
});
const wwwStatefulSet = new kubernetes.apps.v1.StatefulSet('wwwStatefulSet', {
spec: {
selector: {
matchLabels: {
app: 'nginx',
},
},
serviceName: nginxService.metadata.name,
replicas: 3,
template: {
metadata: {
labels: {
app: 'nginx',
},
},
spec: {
terminationGracePeriodSeconds: 10,
containers: [ {
name: 'nginx',
image: '<http://k8s.gcr.io/nginx-slim:0.8|k8s.gcr.io/nginx-slim:0.8>',
ports: [ {
containerPort: 80,
name: 'web',
} ],
volumeMounts: [ {
name: 'www',
mountPath: '/usr/share/nginx/html',
} ],
} ],
},
},
volumeClaimTemplates: [ {
metadata: {
name: 'www',
},
spec: {
accessModes: [ 'ReadWriteOnce' ],
storageClassName: 'my-storage-class',
resources: {
requests: {
storage: '1Gi',
},
},
},
} ],
},
});
billowy-army-68599
bright-horse-50102
04/22/2022, 8:44 AMbillowy-army-68599
bright-horse-50102
04/22/2022, 8:46 AMbillowy-army-68599
bright-horse-50102
04/22/2022, 8:49 AMbillowy-army-68599
bright-horse-50102
04/22/2022, 8:51 AMbillowy-army-68599