在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:cli开源软件地址:https://gitee.com/dapr/cli开源软件介绍:Dapr CLIThe Dapr CLI allows you to setup Dapr on your local dev machine or on a Kubernetes cluster, provides debugging support, launches and manages Dapr instances. Getting startedPrerequisitesOn default, during initialization the Dapr CLI will install the Dapr binaries as well as setup a developer environment to help you get started easily with Dapr. This environment uses Docker containers, therefore Docker needs to be installed. If you prefer to run Dapr without this environment and no dependency on Docker, after installation of the CLI make sure to follow the instructions to initialize Dapr using slim init. Note, if you are a new user, it is strongly recommended to install Docker and use the regular init command.
Installing Dapr CLIUsing script to install the latest releaseWindows Install the latest windows Dapr CLI to powershell -Command "iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex" Linux Install the latest linux Dapr CLI to wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash MacOS Install the latest darwin Dapr CLI to curl -fsSL https://raw.githubusercontent.com/dapr/cli/master/install/install.sh | /bin/bash From the Binary ReleasesEach release of Dapr CLI includes various OSes and architectures. These binary versions can be manually downloaded and installed.
Install Dapr on your local machine (self-hosted)In self-hosted mode, dapr can be initialized using the CLI with the placement, redis and zipkin containers enabled by default(recommended) or without them which also does not require docker to be available in the environment. Initialize Dapr(Prerequisite: Docker is available in the environment - recommended) Use the init command to initialize Dapr. On init, multiple default configuration files and containers are installed along with the dapr runtime binary. Dapr runtime binary is installed under $HOME/.dapr/bin for Mac, Linux and %USERPROFILE%.dapr\bin for Windows. dapr init
Output should look like so: ⌛ Making the jump to hyperspace...✅ Downloaded binaries and completed components set up.ℹ️ daprd binary has been installed to $HOME/.dapr/bin.ℹ️ dapr_placement container is running.ℹ️ dapr_redis container is running.ℹ️ dapr_zipkin container is running.ℹ️ Use `docker ps` to check running containers.✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started
This step creates the following defaults:
Slim InitAlternatively to the above, to have the CLI not install any default configuration files or run Docker containers, use the dapr init --slim Output should look like so: ⌛ Making the jump to hyperspace...✅ Downloaded binaries and completed components set up.ℹ️ daprd binary has been installed to $HOME/.dapr/bin.ℹ️ placement binary has been installed.✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started
Install a specific runtime versionYou can install or upgrade to a specific version of the Dapr runtime using # Install v1.0.0 runtime$ dapr init --runtime-version 1.0.0# Check the versions of CLI and runtime$ dapr --versionCLI version: v1.0.0Runtime version: v1.0.0 Install to a specific Docker networkYou can install the Dapr runtime to a specific Docker network in order to isolate it from the local machine (e.g. to use Dapr from within a Docker container). # Create Docker network$ docker network create dapr-network# Install Dapr to the network$ dapr init --network dapr-network
Uninstall Dapr in a standalone modeUninstalling will remove daprd binary and the placement container (if installed with Docker or the placement binary if not). dapr uninstall
The command above won't remove the redis or zipkin containers by default in case you were using it for other purposes. It will also not remove the default dapr folder that was created on dapr uninstall --all The above command can also be run when Dapr has been installed in a non-docker environment, it will only remove the installed binaries and the default dapr folder in that case.
You should always run a Uninstall Dapr from a specific Docker networkIf previously installed to a specific Docker network, Dapr can be uninstalled with the dapr uninstall --network dapr-network Install Dapr on KubernetesThe init command will install Dapr to a Kubernetes cluster. For more advanced use cases, use our Helm Chart. Note: The default namespace is dapr-system. The installation will appear under the name $ dapr init -k⌛ Making the jump to hyperspace...ℹ️ Note: To install Dapr using Helm, see here: https://docs.dapr.io/getting-started/install-dapr/#install-with-helm-advanced✅ Deploying the Dapr control plane to your cluster...✅ Success! Dapr has been installed to namespace dapr-system. To verify, run "dapr status -k" in your terminal. To get started, go here: https://aka.ms/dapr-getting-started Supplying Helm valuesAll available Helm Chart values can be set by using the dapr init -k --set global.tag=1.0.0 --set dapr_operator.logLevel=error Installing to a custom namespacedapr init -k -n my-namespace Installing with a highly available control plane configdapr init -k --enable-ha=true Installing with mTLS disableddapr init -k --enable-mtls=false Waiting for the Helm install to complete (default timeout is 300s/5m)dapr init -k --wait --timeout 600 Uninstall Dapr on KubernetesTo remove Dapr from your Kubernetes cluster, use the dapr uninstall -k The default timeout is 300s/5m and can be overridden using the dapr uninstall -k --timeout 600 To remove all Dapr Custom Resource Definitions: dapr uninstall -k --all Warning: this will remove any components, subscriptions or configurations that are applied in the cluster at the time of deletion. Upgrade Dapr on KubernetesTo perform a zero downtime upgrade of the Dapr control plane: dapr upgrade -k --runtime-version=1.0.0 The example above shows how to upgrade from your current version to version Supplying Helm valuesAll available Helm Chart values can be set by using the dapr upgrade -k --runtime-version=1.0.0 --set global.tag=my-tag --set dapr_operator.logLevel=error Note: do not use the Launch Dapr and your appThe Dapr CLI lets you debug easily by launching both Dapr and your app.Logs from both the Dapr Runtime and your app will be displayed in real time! Example of launching Dapr with a node app: dapr run --app-id nodeapp node app.js Example of launching Dapr with a node app listening on port 3000: dapr run --app-id nodeapp --app-port 3000 node app.js Example of launching Dapr on HTTP port 6000: dapr run --app-id nodeapp --app-port 3000 --dapr-http-port 6000 node app.js Example of launching Dapr on gRPC port 50002: dapr run --app-id nodeapp --app-port 3000 --dapr-grpc-port 50002 node app.js Example of launching Dapr within a specific Docker network: dapr init --network dapr-networkdapr run --app-id nodeapp --placement-host-address dapr_placement node app.js
Use gRPCIf your app uses gRPC instead of HTTP to receive Dapr events, run the CLI with the following command: dapr run --app-id nodeapp --app-protocol grpc --app-port 6000 node app.js The example above assumed your app port is 6000. Publish/SubscribeTo use pub-sub with your app, make sure that your app has a Launch Dapr and your app: dapr run --app-id nodeapp --app-port 3000 node app.js Publish a message: The Publish a message:
dapr publish --publish-app-id nodeapp --pubsub pubsub --topic myevent --data '{ "name": "yoda" }'
dapr publish --publish-app-id nodeapp --pubsub pubsub --topic myevent --data "{ \"name\": \"yoda\" }" InvokingTo test your endpoints with Dapr, simply expose any HTTP endpoint.For this sample, we'll assume a node app listening on port 3000 with a Launch Dapr and your app: dapr run --app-id nodeapp --app-port 3000 node app.js Note: To choose a non-default components folder, use the --components-path option. Invoke your app: dapr invoke --app-id nodeapp --method mymethod Specify a verb: By default, Dapr will use the dapr invoke --app-id nodeapp --method mymethod --verb GET ListTo list all Dapr instances running on your machine: dapr list To list all Dapr instances running in a Kubernetes cluster: dapr list --kubernetes To list all Dapr instances but return output as JSON or YAML (e.g. for consumption by other tools): dapr list --output jsondapr list --output yaml Check system services (control plane) statusCheck Dapr's system services (control plane) health status in a Kubernetes cluster: dapr status --kubernetes Check mTLS statusTo check if Mutual TLS is enabled in your Kubernetes cluster: dapr mtls --kubernetes Export TLS certificatesTo export the root cert, issuer cert and issuer key created by Dapr from a Kubernetes cluster to a local path: dapr mtls export This will save the certs to the working directory. To specify a custom directory: dapr mtls export -o certs Check root certificate expirydapr mtls expiry This can be used when upgrading to a newer version of Dapr, as it's recommended to carry over the existing certs for a zero downtime upgrade. List ComponentsTo list all Dapr components on Kubernetes: dapr components --kubernetes Use non-default Components PathTo use a custom path for component definitions dapr run --components-path [custom path] List ConfigurationsTo list all Dapr configurations on Kubernetes: dapr configurations --kubernetes StopUse dapr stop myAppID You can also stop multiple Dapr apps dapr stop myAppID1 myAppID2 Enable profilingIn order to enable profiling, use the dapr run --app-id nodeapp --app-port 3000 node app.js --enable-profiling Dapr will automatically assign a profile port for you.If you want to manually assign a profiling port, use the dapr run --app-id nodeapp --app-port 3000 node app.js --enable-profiling --profile-port 7777 Set metrics server portTo change the metrics server port used by Dapr, set the dapr run --app-id nodeapp --app-port 3000 node app.js --metrics-port 5040 Set log levelIn order to set the Dapr runtime log verbosity level, use the dapr run --app-id nodeapp --app-port 3000 node app.js --log-level debug This sets the Dapr log level to Enable SSL when invoking an appIf your app is listening on dapr run --app-id nodeapp --app-port 3000 node app.js --app-ssl This will have Dapr invoke the app over an insecure SSL channel. The default is false. Running sidecar onlyYou can run Dapr's sidecar only ( dapr run --app-id myapp --dapr-http-port 3005 --dapr-grpc-port 50001 Generate shell completion scriptsTo generate shell completion scripts: dapr completion Enable Unix domain socketIn order to enable Unix domain socket to connect Dapr API server, use the $ dapr run --app-id nodeapp --unix-domain-socket node app.js Dapr will automatically create a Unix domain socket to connect Dapr API server. If you want to invoke your app, also use this flag: $ dapr invoke --app-id nodeapp --unix-domain-socket --method mymethod Enable Unix domain socketIn order to enable Unix domain socket to connect Dapr API server, use the $ dapr run --app-id nodeapp --unix-domain-socket node app.js Dapr will automatically create a Unix domain socket to connect Dapr API server. If you want to invoke your app, also use this flag: $ dapr invoke --app-id nodeapp --unix-domain-socket --method mymethod For more details, please run the command and check the examples to apply to your shell. Reference for the Dapr CLISee the Reference Guide for more information about individual Dapr commands. Contributing to Dapr CLISee the Development Guide to get started with building and developing. Code of ConductPlease refer to our Dapr Community Code of Conduct |
请发表评论