Skip to content

Service

Bases: DuploTenantResourceV2

Duplocloud Service Resource

This resource is used to manage services in Duplocloud. Using the duploctl command line tool, you can manage services with actions:

Basic CLI Use
duploctl service <action>

apply

Apply a service.

bulk_update_image

Bulk Update Images

Bulk update the image of multiple services.

Basic CLI Use
duploctl service bulk_update_image -S <service-name-1> <image-name-1> -S <service-name-2> <image-name-2>

Parameters:

Name Type Description Default
serviceimage SERVICEIMAGE

Takes n sets of two arguments, service name and image name. e.g., -S service1 image1:tag -S service2 image2:tag

required

Returns:

Name Type Description
message dict

A message about success.

create

Create a service.

Create a service in Duplocloud.

Basic CLI Use

duploctl service create --file service.yaml
Contents of the service.yaml file
Name: duploctl
DockerImage: nginx:latest
Replicas: 1
Cloud: 0
IsLBSyncedDeployment: true
AgentPlatform: 7
ReplicasMatchingAsgName: null
HPASpecs:
  maxReplicas: 3
  metrics:
  - resource:
      name: cpu
      target:
        averageUtilization: 80
        type: Utilization
    type: Resource
  minReplicas: 2
IsDaemonset: false
OtherDockerHostConfig: ''
OtherDockerConfig: '{"Env":null}'
NetworkId: default

Create and Wait

Use the global --wait flag to wait for the service to be created and all replicas in a ready status.

duploctl service create --file service.yaml --wait

Parameters:

Name Type Description Default
body BODY

The service to create.

required

Returns:

Name Type Description
message dict

Success message.

current_replicaset

Get the current replicaset for a service.

Finds the name of the underlying replicaset for a named service.

info

This is not a cli command. It's primarily used internally but could be useful in a custom script.

Parameters:

Name Type Description Default
name str

The name of the service to get replicaset for.

required

Returns:

Type Description
str

The current replicaset for the service.

Raises:

Type Description
DuploError

If the service could not be found.

delete

Delete a service.

Delete a service in Duplocloud.

Basic CLI Use
duploctl service delete <service-name>

Parameters:

Name Type Description Default
name NAME

The name of the service to delete.

required

Returns:

Name Type Description
message dict

Success message.

expose

Expose a service.

Exposes a service through a load balancer. Attaches a Duplocloud service lb configuration to the service.

Basic CLI Use
duploctl service expose <service-name> --lb-type applicationlb --container-port 80 --external-port 80                               --visibility public --mode docker-mode --health-check-url / --protocol http

Parameters:

Name Type Description Default
container-port

The internal port of the container to expose.

required
external-port

The external port exposed by the load balancer. This is not used for targetgrouponly or k8clusterip load balancer types.

required
lb-type

The load balancer type. Valid options are ['applicationlb', 'k8clusterip', 'k8nodeport', 'networklb', 'targetgrouponly'].

required
protocol PROTOCOL

The protocol to use, based on lb_type - applicationlb: http, https - networklb: tcp, udp, tls - targetgrouponly: http, https - k8clusterip: tcp, udp - k8nodeport: tcp, udp

None
visibility LOAD_BALANCER_VISIBILITY

The load balancer visibility. Valid options are 'public' or 'private'.

'public'
mode LOAD_BALANCER_MODE

The load balancer application mode. Valid options are 'docker-mode' or 'native-app'.

'docker-mode'
health_check_url HEALTH_CHECK_URL

The health check URL path. This must be empty for networklb, as it does not support health check paths.

None

Returns:

Type Description
dict

A success message indicating the exposure status.

Raises:

Type Description
DuploError

If the service could not be exposed.

find

Find a service by name.

First we try for the endpoint that gives one by name. Otherwise we default to finding it in the list.

Usage
duploctl service find <service-name>

Returns:

Name Type Description
service dict

The full object for a service.

image_from_body

Get the image from a service body.

info

This is not a cli command. It's primarily used internally but could be useful in a custom script.

Parameters:

Name Type Description Default
body dict

The body of the service.

required

Returns:

Name Type Description
image str

The image for the service.

list

Retrieve a List of Service

cli usage
duploctl service list

Returns:

Name Type Description
list list

A list of Service.

logs

Service Logs

Get the logs for a service. This will be an aggregate of all logs from the pods. The pod names will be prefixed on each line.

Get the logs for a service.

Basic CLI Use
duploctl service logs <service-name>
Watch Logs

This command supports the global --wait. Waits and watches for new logs. As new logs come they are printed to the console. Use ctrl+c to stop watching.

duploctl service logs myapp --wait --loglevel INFO

Parameters:

Name Type Description Default
name NAME

The name of the service to get logs for.

required

Returns:

Name Type Description
logs dict

A big list of logs.

name_from_body

Service name from body.

Simply returns the services name given an entire service object.

info

This is not a cli command. It's primarily used internally but could be useful in a custom script.

Parameters:

Name Type Description Default
body dict

The service object.

required

Returns:

Name Type Description
name str

The name of the service.

pods

Get Pods

Get a list of all of the pods owned by this service.

Basic CLI Use
duploctl service pods <service-name>

Parameters:

Name Type Description Default
name NAME

The name of the service to get pods for.

required

Returns:

Name Type Description
message dict

A list of pods for the service.

Raises:

Type Description
DuploError

If the service could not be found.

restart

Restart a service.

Restart a service. Cause kubernetes to do a full rollover of it's replicaset. This does honor the deployment strategy settings.

Basic CLI Use
duploctl service restart <service-name>
Wait for Restart

This command supports the global --wait. Waits for the desired count of pods to become ready.

duploctl service restart myapp --wait --loglevel INFO

Parameters:

Name Type Description Default
name NAME

The name of the service to restart.

required

Returns:

Name Type Description
message dict

A success message if the service was restarted successfully.

Raises:

Type Description
DuploError

If the service could not be restarted.

rollback

Rollback Service

Roll back a service to a specific revision (if provided) or the last known good state.

Usage
duploctl service rollback <service-name>
duploctl service rollback <service-name> --to-revision 2

Parameters:

Name Type Description Default
name NAME

The name of the service to roll back.

required
to_revision TO_REVISION

The revision number to roll back to.

None

Returns:

Name Type Description
message dict

A success message indicating the rollback status.

Raises:

Type Description
DuploError

If the service could not be rollback.

start

Start a service.

Start a service.

Basic CLI Use
duploctl service start <service-name>
duploctl service start --all
duploctl service start --targets service1 service2 service3
Wait for Start

This command supports the global --wait. Waits for the desired count of pods to become ready.

duploctl service start myapp --wait --loglevel INFO

Parameters:

Name Type Description Default
name NAME

The name of the service to start.

None
all ALL

Boolean flag to start all services. Defaults to False.

False
targets TARGETS

List of service names to start. Cannot be used with name or all.

None

Returns:

Type Description
dict

A summary containing services that were started successfully and those that encountered errors.

Raises:

Type Description
DuploError

If the service could not be started.

stop

Stop a service.

Stop a service.

Basic CLI Use
duploctl service stop <service-name>
duploctl service stop --all
duploctl service stop --targets service1 service2 service3
Wait for Stop

This command supports the global --wait. Waits for all pods to disappear.

duploctl service stop myapp --wait --loglevel INFO

Parameters:

Name Type Description Default
name NAME

The name of the service to stop.

None
all ALL

Boolean flag to stop all services. Defaults to False.

False
targets TARGETS

List of service names to stop. Cannot be used with name or all.

None

Returns:

Type Description
dict

A summary containing services that were stopped successfully and those that encountered errors.

Raises:

Type Description
DuploError

If the service could not be stopped.

update

Update a service.

Update the state of a service.

Basic CLI Use

Update the replicas to 3 for a service.

duploctl service update <service-name> --replace Replicas 3

Parameters:

Name Type Description Default
name NAME

The name of the service to update.

required
body BODY

The body of the service to update.

None
patches PATCHES

A list of JSON patches as args to apply to the service. The options are --add, --remove, --replace, --move, and --copy. Then followed by <path> and <value> for --add, --replace, and --test.

None
wait

Whether to wait for the service to update.

required

update_env

Update environment variables

Updates the environment variables of a service. If service has no environment variables set, use -strat replace to set new values. You may pass any number of --setvar flags to set multiple environment variables.

Basic CLI Use
duploctl service update_env <service-name> --strategy <replace,merge> --setvar <key> <value>

Example: Update all environment variables All variables for the service would be replaced by the variables in the command. This is a full state refresh.

duploctl service update_env myapp --strategy replace --setvar FOO bar --setvar MESSAGE "Hello?"

Add a new variable
duploctl service update_env myapp --strategy merge --setvar NEW_VAR "New Value"

Parameters:

Name Type Description Default
name NAME

The name of the service to update.

required
setvar SETVAR

A list of key value pairs to set as environment variables.

required
strategy STRATEGY

The merge strategy to use for env vars. Valid options are "merge" or "replace". Default is merge.

required
deletevar DELETEVAR

A list of keys to delete from the environment variables.

required

update_image

Update the image of a service.

Basic CLI Use
duploctl service update_image <service-name> <service-image>
duploctl service update_image <service-name> --container-image <side-car-container> <container-image>
duploctl service update_image <service-name> --init-container-image <init-container> <init-container-image>
Update Image and Wait

Waits till the desired count of pods all reach the running state with the new image.

duploctl service update_image myapp myimage:latest --wait --loglevel INFO

Parameters:

Name Type Description Default
name NAME

The name of the service to update.

required
image IMAGE

The new image to use for the service.

None
container_image CONTAINER_IMAGE

A list of key-value pairs to set as sidecar container image.

None
init_container_image INIT_CONTAINER_IMAGE

A list of key-value pairs to set as init container image.

None

Returns:

Name Type Description
message dict

Success message

update_pod_label

Update pod labels

Updates the labels on the pod of a service. If service has no pod labels set, use -strat replace to set new values.

Basic CLI Use
duploctl service update_pod_label <service-name> --setvar env-key1 env-val1 --setvar env-key2 env-val2 --setvar env-key3 env-val3 --strategy merge --host $DUPLO_HOST --tenant $DUPLO_TENANT --token $DUPLO_TOKEN
duploctl service update_pod_label <service-name> --setvar env-key1 env-val1 --setvar env-key2 env-val2 --strategy replace --host $DUPLO_HOST --tenant $DUPLO_TENANT --token $DUPLO_TOKEN
duploctl service update_pod_label <service-name> --deletevar env-key1 --host $DUPLO_HOST --tenant $DUPLO_TENANT --token $DUPLO_TOKEN

Args: name: The name of the service to update. setvar: A list of key value pairs to set as environment variables. strategy: The merge strategy to use for env vars. Valid options are "merge" or "replace". Default is merge. deletevar: A list of keys to delete from the environment variables.

Returns:

Name Type Description
message

A message about success.

update_replicas

Scale Service

Update the number of replicas for a service.

Basic CLI Use
duploctl service update_replicas <service-name> <replicas>
Wait for Scaling

The update replicas supports the global --wait flag. This will wait till the number of pods match the desired count.

duploctl service update_replicas myapp 99 --wait

Parameters:

Name Type Description Default
name NAME

The name of the service to update.

required
replica REPLICAS

Number of replicas to set for service.

required