|
| 1 | +apiVersion: apps/v1 |
| 2 | +kind: Deployment |
| 3 | +metadata: |
| 4 | + name: {{ .Release.Name }}-api-server |
| 5 | + namespace: {{ .Release.Namespace }} |
| 6 | +spec: |
| 7 | + # Note: replicas > 1 is not well tested, and requires a PVC that supports ReadWriteMany. |
| 8 | + replicas: {{ .Values.apiService.replicas }} |
| 9 | + strategy: |
| 10 | + type: Recreate |
| 11 | + selector: |
| 12 | + matchLabels: |
| 13 | + app: {{ .Release.Name }}-api |
| 14 | + template: |
| 15 | + metadata: |
| 16 | + labels: |
| 17 | + app: {{ .Release.Name }}-api |
| 18 | + spec: |
| 19 | + automountServiceAccountToken: {{ .Values.kubernetesCredentials.useApiServerCluster }} |
| 20 | + serviceAccountName: {{ .Release.Name }}-api-sa |
| 21 | + {{- with $.Values.podSecurityContext }} |
| 22 | + securityContext: |
| 23 | + {{- toYaml . | nindent 8 }} |
| 24 | + {{- end }} |
| 25 | + containers: |
| 26 | + - name: skypilot-api |
| 27 | + image: {{ .Values.apiService.image }} |
| 28 | + imagePullPolicy: Always |
| 29 | + {{- with $.Values.securityContext }} |
| 30 | + securityContext: |
| 31 | + {{- toYaml . | nindent 10 }} |
| 32 | + {{- end }} |
| 33 | + resources: |
| 34 | + {{- toYaml .Values.apiService.resources | nindent 10 }} |
| 35 | + env: |
| 36 | + - name: SKYPILOT_DEV |
| 37 | + value: {{ .Values.apiService.skypilotDev | quote }} |
| 38 | + {{- if .Values.gcpCredentials.enabled }} |
| 39 | + - name: GOOGLE_APPLICATION_CREDENTIALS |
| 40 | + value: /root/gcp-cred.json |
| 41 | + {{- end }} |
| 42 | + {{- if .Values.kubernetesCredentials.inclusterNamespace }} |
| 43 | + - name: SKYPILOT_IN_CLUSTER_NAMESPACE |
| 44 | + value: {{ .Values.kubernetesCredentials.inclusterNamespace }} |
| 45 | + {{- end }} |
| 46 | + # Use tini as the init process |
| 47 | + command: ["tini", "--"] |
| 48 | + # Start API server in foreground (if supported) to: |
| 49 | + # 1. Bypass the healthz check of `sky api start`, let kubernetes probes manage the lifecycle directly. |
| 50 | + # 2. Capture all logs in container to stdout/stderr, bypass in-container log file overhead. |
| 51 | + # 3. Exec ensures the process is a direct child of tini, enables correct signal handling. |
| 52 | + # Note: this comment is moved here to avoid appearing in the final start script. |
| 53 | + args: |
| 54 | + - /bin/sh |
| 55 | + - -c |
| 56 | + - | |
| 57 | + set -e |
| 58 | + {{- if .Values.apiService.preDeployHook }} |
| 59 | + {{ .Values.apiService.preDeployHook | nindent 10 }} |
| 60 | + {{- end }} |
| 61 | + {{- if .Values.apiService.config }} |
| 62 | + mkdir -p /root/.sky |
| 63 | + echo "Copying config.yaml from ConfigMap \`skypilot-config\` to /root/.sky/config.yaml" |
| 64 | + # The configmap serves as the ground truth for the config.yaml file. |
| 65 | + # Any local changes to the config.yaml file will be overwritten by the contents of the configmap. |
| 66 | + cp /tmp/config.yaml /root/.sky/config.yaml |
| 67 | + {{- end }} |
| 68 | +
|
| 69 | + if sky api start -h | grep -q -- "--foreground"; then |
| 70 | + exec sky api start --deploy --foreground |
| 71 | + else |
| 72 | + # For backward compatibility, run in background if --foreground is not supported. |
| 73 | + # TODO(aylei): this will bedropped in 0.11.0. |
| 74 | + if sky api start --deploy; then |
| 75 | + tail -n+0 -f /root/.sky/api_server/server.log |
| 76 | + else |
| 77 | + cat /root/.sky/api_server/server.log |
| 78 | + fi |
| 79 | + fi |
| 80 | + ports: |
| 81 | + - containerPort: 46580 |
| 82 | + livenessProbe: |
| 83 | + httpGet: |
| 84 | + path: /api/health |
| 85 | + port: 46580 |
| 86 | + periodSeconds: 30 |
| 87 | + readinessProbe: |
| 88 | + httpGet: |
| 89 | + path: /api/health |
| 90 | + port: 46580 |
| 91 | + periodSeconds: 30 |
| 92 | + volumeMounts: |
| 93 | + {{- if .Values.storage.enabled }} |
| 94 | + - name: state-volume |
| 95 | + mountPath: /root/.sky |
| 96 | + subPath: .sky |
| 97 | + - name: state-volume |
| 98 | + mountPath: /root/.ssh # To preserve the SSH keys for the user when using the API server |
| 99 | + subPath: .ssh |
| 100 | + {{- end }} |
| 101 | + {{- if .Values.apiService.config }} |
| 102 | + - name: skypilot-config |
| 103 | + mountPath: /tmp/config.yaml |
| 104 | + subPath: config.yaml |
| 105 | + {{- end }} |
| 106 | + {{- if .Values.awsCredentials.enabled }} |
| 107 | + - name: aws-config |
| 108 | + mountPath: /root/.aws |
| 109 | + readOnly: true |
| 110 | + {{- end }} |
| 111 | + {{- if .Values.gcpCredentials.enabled }} |
| 112 | + - name: gcp-config |
| 113 | + mountPath: /root/.config/gcloud |
| 114 | + - name: gcp-credentials |
| 115 | + mountPath: /root/gcp-cred.json |
| 116 | + subPath: gcp-cred.json |
| 117 | + {{- end }} |
| 118 | + {{- if .Values.kubernetesCredentials.useKubeconfig }} |
| 119 | + - name: kube-config |
| 120 | + mountPath: /root/.kube |
| 121 | + {{- end }} |
| 122 | + initContainers: |
| 123 | + {{- if .Values.awsCredentials.enabled }} |
| 124 | + - name: create-aws-credentials |
| 125 | + image: {{ .Values.apiService.image }} |
| 126 | + command: ["/bin/sh", "-c"] |
| 127 | + args: |
| 128 | + - | |
| 129 | + echo "Setting up AWS credentials..." |
| 130 | + if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then |
| 131 | + echo "AWS credentials found in environment variables." |
| 132 | + aws configure set aws_access_key_id "$AWS_ACCESS_KEY_ID" |
| 133 | + aws configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY" |
| 134 | + echo "Credentials file created successfully." |
| 135 | + else |
| 136 | + echo "AWS credentials not found in environment variables. Skipping credentials setup." |
| 137 | + sleep 600 |
| 138 | + fi |
| 139 | + env: |
| 140 | + - name: AWS_ACCESS_KEY_ID |
| 141 | + valueFrom: |
| 142 | + secretKeyRef: |
| 143 | + name: aws-credentials |
| 144 | + key: aws_access_key_id |
| 145 | + - name: AWS_SECRET_ACCESS_KEY |
| 146 | + valueFrom: |
| 147 | + secretKeyRef: |
| 148 | + name: aws-credentials |
| 149 | + key: aws_secret_access_key |
| 150 | + volumeMounts: |
| 151 | + - name: aws-config |
| 152 | + mountPath: /root/.aws |
| 153 | + {{- end }} |
| 154 | + {{- if .Values.gcpCredentials.enabled }} |
| 155 | + - name: setup-gcp-credentials |
| 156 | + image: google/cloud-sdk:latest |
| 157 | + command: ["/bin/sh", "-c"] |
| 158 | + env: |
| 159 | + - name: GOOGLE_APPLICATION_CREDENTIALS |
| 160 | + value: /root/gcp-cred.json |
| 161 | + args: |
| 162 | + - | |
| 163 | + gcloud auth activate-service-account --key-file=/root/gcp-cred.json |
| 164 | + gcloud config set project {{ .Values.gcpCredentials.projectId }} |
| 165 | + volumeMounts: |
| 166 | + - name: gcp-credentials |
| 167 | + mountPath: /root/gcp-cred.json |
| 168 | + subPath: gcp-cred.json |
| 169 | + - name: gcp-config |
| 170 | + mountPath: /root/.config/gcloud |
| 171 | + {{- end }} |
| 172 | + volumes: |
| 173 | + {{- if .Values.storage.enabled }} |
| 174 | + - name: state-volume |
| 175 | + persistentVolumeClaim: |
| 176 | + claimName: {{ .Release.Name }}-state |
| 177 | + {{- else }} |
| 178 | + - name: state-volume |
| 179 | + emptyDir: {} |
| 180 | + {{- end }} |
| 181 | + {{- if .Values.awsCredentials.enabled }} |
| 182 | + - name: aws-config |
| 183 | + emptyDir: {} |
| 184 | + {{- end }} |
| 185 | + |
| 186 | + {{- if .Values.gcpCredentials.enabled }} |
| 187 | + - name: gcp-credentials |
| 188 | + secret: |
| 189 | + secretName: gcp-credentials |
| 190 | + - name: gcp-config |
| 191 | + emptyDir: {} |
| 192 | + {{- end }} |
| 193 | + {{- if .Values.kubernetesCredentials.useKubeconfig }} |
| 194 | + - name: kube-config |
| 195 | + secret: |
| 196 | + secretName: {{ .Values.kubernetesCredentials.kubeconfigSecretName }} |
| 197 | + {{- end }} |
| 198 | + {{- if .Values.apiService.config }} |
| 199 | + - name: skypilot-config |
| 200 | + configMap: |
| 201 | + name: {{ .Release.Name }}-config |
| 202 | + {{- end }} |
0 commit comments