GoogleCloudPlatform / deploymentmanager-samples

Deployment Manager samples and templates.
Apache License 2.0
939 stars 718 forks source link

add openapi/v2 support to gke/python sample code #544

Closed ingernet closed 4 years ago

ingernet commented 4 years ago

Sample code for the following files wasn't working after the move to openapi/v2:

This update helps folks new to deployment-manager at least get a hello-world going.

This code works after refactor:

# DEPLOY THE CLUSTER
$ gcloud deployment-manager deployments create ingernet --template cluster.py --properties zone:$ZONE
The fingerprint of the deployment is o3UIihCshClYWmcZCgwrcA==
Waiting for create [operation-1583425714879-5a01e07437c54-9a198cf2-650426d5]...done.          
Create operation operation-1583425714879-5a01e07437c54-9a198cf2-650426d5 completed successfully.
NAME                      TYPE                                   STATE      ERRORS  INTENT
ingernet-cluster-py       container.v1.cluster                   COMPLETED  []
ingernet-cluster-py-type  deploymentmanager.v2beta.typeProvider  COMPLETED  []

# DEPLOY THE DEPLOYMENT
$ gcloud deployment-manager deployments create ${NAME}-web --template deployment.py \
> --properties clusterType:${NAME}-cluster-py-type,image:${IMAGE},port:${PORT}
The fingerprint of the deployment is cuBGZETtHX7AHd3MeJTcmw==
Waiting for create [operation-1583426395133-5a01e2fcf578e-817735f2-1c6f1eb3]...done.          
Create operation operation-1583426395133-5a01e2fcf578e-817735f2-1c6f1eb3 completed successfully.
NAME                                   TYPE                           STATE      ERRORS  INTENT
ingernet-web-deployment-py-deployment  <REDACTED-PROJECT>/ingernet-clu  COMPLETED  []
                                       ster-py-type:/apis/apps/v1bet
                                       a1/namespaces/{namespace}/dep
                                       loyments/{name}
ingernet-web-deployment-py-service    <REDACTED-PROJECT>/ingernet-clu  COMPLETED  []
                                       ster-py-type:/api/v1/namespac
                                       es/{namespace}/services/{name
                                       }

# GET CREDENTIALS
$ gcloud container clusters get-credentials ${NAME}-cluster-py --zone ${ZONE}
Fetching cluster endpoint and auth data.
kubeconfig entry generated for ingernet-cluster-py.

# LOOK FOR DEPLOYMENTS AND SERVICES
$ kubectl get deployments
NAME                                    READY   UP-TO-DATE   AVAILABLE   AGE
ingernet-web-deployment-py-deployment   1/1     1            1           55s

$ kubectl get services
NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
ingernet-web-deployment-py-service   NodePort    <REDACTED-IP>   <none>        80:32709/TCP   66s
kubernetes                           ClusterIP   <REDACTED-CLUSTER-IP>     <none>        443/TCP        9m59s

# FIRE UP PORT FORWARDING
$ kubectl port-forward $(\
>   kubectl get pods --output=jsonpath="{.items[0].metadata.name}") \
>   9999:${PORT}
Forwarding from 127.0.0.1:9999 -> 80
Forwarding from [::1]:9999 -> 80

# IN A NEW WINDOW, CURL localhost:9999
$ curl http://localhost:9999
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...SNIP...

# IN THAT SAME NEW WINDOW, SET UP YOUR ENV VARIABLES
$NODES=$(kubectl get nodes --output=name | sed 's|node/||g')
$NODE_HOST=$(shuf -n1 -e ${NODES})
$ NODE_PORT=$(\
>   kubectl get services \
>   --selector=id=deployment-manager \
>   --output=jsonpath="{.items[0].spec.ports[0].nodePort}")

# ALSO IN THE NEW WINDOW, SSH INTO THE NODE
# (i had to specify the zone in my command because it was different from the profile i was using)
$ gcloud compute ssh ${NODE_HOST} --ssh-flag="-L ${NODE_PORT}:localhost:${NODE_PORT}" --zone=us-central1-b
Warning: Permanently added 'compute.1740778203171821088' (ED25519) to the list of known hosts.

Welcome to Kubernetes v1.14.10-gke.17!
...SNIP...
googlebot commented 4 years ago

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

ingernet commented 4 years ago

@googlebot I signed it!

googlebot commented 4 years ago

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.