k8s.io/client-go@v0.22.2/examples/create-update-delete-deployment/README.md (about)

     1  # Create, Update & Delete Deployment
     2  
     3  This example program demonstrates the fundamental operations for managing on
     4  [Deployment][1] resources, such as `Create`, `List`, `Update` and `Delete`.
     5  
     6  You can adopt the source code from this example to write programs that manage
     7  other types of resources through the Kubernetes API.
     8  
     9  ## Running this example
    10  
    11  Make sure you have a Kubernetes cluster and `kubectl` is configured:
    12  
    13      kubectl get nodes
    14  
    15  Compile this example on your workstation:
    16  
    17  ```
    18  cd create-update-delete-deployment
    19  go build -o ./app
    20  ```
    21  
    22  Now, run this application on your workstation with your local kubeconfig file:
    23  
    24  ```
    25  ./app
    26  # or specify a kubeconfig file with flag
    27  ./app -kubeconfig=$HOME/.kube/config
    28  ```
    29  
    30  Running this command will execute the following operations on your cluster:
    31  
    32  1. **Create Deployment:** This will create a 2 replica Deployment. Verify with
    33     `kubectl get pods`.
    34  2. **Update Deployment:** This will update the Deployment resource created in
    35     previous step by setting the replica count to 1 and changing the container
    36     image to `nginx:1.13`. You are encouraged to inspect the retry loop that
    37     handles conflicts. Verify the new replica count and container image with
    38     `kubectl describe deployment demo`.
    39  3. **List Deployments:** This will retrieve Deployments in the `default`
    40     namespace and print their names and replica counts.
    41  4. **Delete Deployment:** This will delete the Deployment object and its
    42     dependent ReplicaSet resource. Verify with `kubectl get deployments`.
    43  
    44  Each step is separated by an interactive prompt. You must hit the
    45  <kbd>Return</kbd> key to proceed to the next step. You can use these prompts as
    46  a break to take time to run `kubectl` and inspect the result of the operations
    47  executed.
    48  
    49  You should see an output like the following:
    50  
    51  ```
    52  Creating deployment...
    53  Created deployment "demo-deployment".
    54  -> Press Return key to continue.
    55  
    56  Updating deployment...
    57  Updated deployment...
    58  -> Press Return key to continue.
    59  
    60  Listing deployments in namespace "default":
    61   * demo-deployment (1 replicas)
    62  -> Press Return key to continue.
    63  
    64  Deleting deployment...
    65  Deleted deployment.
    66  ```
    67  
    68  ## Cleanup
    69  
    70  Successfully running this program will clean the created artifacts. If you
    71  terminate the program without completing, you can clean up the created
    72  deployment with:
    73  
    74      kubectl delete deploy demo-deployment
    75  
    76  ## Troubleshooting
    77  
    78  If you are getting the following error, make sure Kubernetes version of your
    79  cluster is v1.6 or above in `kubectl version`:
    80  
    81      panic: the server could not find the requested resource
    82  
    83  [1]: https://kubernetes.io/docs/user-guide/deployments/