[{"data":1,"prerenderedAt":704},["ShallowReactive",2],{"docs-\u002Fdocs\u002Fapplications":3},{"id":4,"title":5,"body":6,"description":696,"extension":697,"meta":698,"navigation":699,"path":700,"seo":701,"stem":702,"__hash__":703},"docs\u002Fdocs\u002Fapplications\u002Findex.md","Applications overview",{"type":7,"value":8,"toc":689},"minimark",[9,13,26,31,147,151,161,304,308,321,368,371,551,584,601,615,619,622,642,645,649,685],[10,11,5],"h1",{"id":12},"applications-overview",[14,15,16,17,21,22,25],"p",{},"An application is everything one piece of software needs on your cluster: groups of containers or VMs, the volumes they mount, an optional PostgreSQL or ClickHouse service, and an optional HAProxy load balancer. You describe it in an ",[18,19,20],"code",{},"application.yaml"," and ",[18,23,24],{},"sg application deploy"," makes it so.",[27,28,30],"h2",{"id":29},"the-pieces","The pieces",[32,33,34,47],"table",{},[35,36,37],"thead",{},[38,39,40,44],"tr",{},[41,42,43],"th",{},"Piece",[41,45,46],{},"What it is",[48,49,50,70,96,113,127,137],"tbody",{},[38,51,52,59],{},[53,54,55],"td",{},[56,57,58],"strong",{},"Group",[53,60,61,62,65,66,69],{},"A set of identical instances: ",[18,63,64],{},"count"," copies of one image, each pinned to a cluster member. Containers by default, or ",[18,67,68],{},"type: vm",".",[38,71,72,77],{},[53,73,74],{},[56,75,76],{},"Instance",[53,78,79,80,83,84,87,88,91,92,95],{},"One copy. Keyed ",[18,81,82],{},"\u003Cgroup>-\u003Cn>"," in the spec (",[18,85,86],{},"web-0","), named ",[18,89,90],{},"\u003Capp>-\u003Cgroup>-\u003Cn>"," in LXD (",[18,93,94],{},"shop-web-0",").",[38,97,98,103],{},[53,99,100],{},[56,101,102],{},"Volume",[53,104,105,106,109,110,69],{},"A storage volume on a member's pool, mounted into instances. ",[18,107,108],{},"filesystem"," or ",[18,111,112],{},"block",[38,114,115,120],{},[53,116,117],{},[56,118,119],{},"Service",[53,121,122,123,126],{},"PostgreSQL or ClickHouse, installed and configured by ",[18,124,125],{},"sg"," inside a single-instance VM group.",[38,128,129,134],{},[53,130,131],{},[56,132,133],{},"Load balancer",[53,135,136],{},"One HAProxy instance that spreads a port across a group's instances.",[38,138,139,144],{},[53,140,141],{},[56,142,143],{},"Generation",[53,145,146],{},"A numbered record of a deploy that finished and passed every check. Rollback goes back one.",[27,148,150],{"id":149},"the-lifecycle","The lifecycle",[152,153,159],"pre",{"className":154,"code":156,"language":157,"meta":158},[155],"language-text","init ──► plan ──► deploy ──► status\n                    │\n                    ├── restart   (no new generation)\n                    ├── scale     (edits the spec, deploys, new generation)\n                    ├── upgrade   (edits the spec, deploys, new generation)\n                    ├── rollback  (redeploys generation N-1 as a new generation)\n                    └── destroy   (removes sg-owned instances and volumes)\n","text","",[18,160,156],{"__ignoreMap":158},[32,162,163,176],{},[35,164,165],{},[38,166,167,170,173],{},[41,168,169],{},"Command",[41,171,172],{},"Effect",[41,174,175],{},"New generation?",[48,177,178,191,203,219,231,246,261,274,289],{},[38,179,180,185,188],{},[53,181,182],{},[18,183,184],{},"init",[53,186,187],{},"Local only. Validates and registers the spec.",[53,189,190],{},"no",[38,192,193,198,201],{},[53,194,195],{},[18,196,197],{},"plan",[53,199,200],{},"Read-only. Prints the plan and its hash.",[53,202,190],{},[38,204,205,210,216],{},[53,206,207],{},[18,208,209],{},"deploy",[53,211,212,215],{},[56,213,214],{},"Changes the cluster."," Deploys, then checks health and exposure.",[53,217,218],{},"yes, when it finishes OK",[38,220,221,226,229],{},[53,222,223],{},[18,224,225],{},"status",[53,227,228],{},"Read-only. State and health per instance.",[53,230,190],{},[38,232,233,238,244],{},[53,234,235],{},[18,236,237],{},"restart",[53,239,240,243],{},[56,241,242],{},"Interrupts service."," Restarts instances and checks health.",[53,245,190],{},[38,247,248,253,258],{},[53,249,250],{},[18,251,252],{},"scale",[53,254,255],{},[56,256,257],{},"Edits the spec and the cluster.",[53,259,260],{},"yes",[38,262,263,268,272],{},[53,264,265],{},[18,266,267],{},"upgrade",[53,269,270],{},[56,271,257],{},[53,273,260],{},[38,275,276,281,286],{},[53,277,278],{},[18,279,280],{},"rollback",[53,282,283,285],{},[56,284,214],{}," Redeploys generation N-1.",[53,287,288],{},"yes (N+1)",[38,290,291,296,302],{},[53,292,293],{},[18,294,295],{},"destroy",[53,297,298,301],{},[56,299,300],{},"Deletes"," owned instances and their volumes.",[53,303,190],{},[27,305,307],{"id":306},"your-app-ships-as-an-lxd-image","Your app ships as an LXD image",[14,309,310,311,313,314,316,317,320],{},"There's no build step and no cloud-init field in ",[18,312,20],{},". A group runs exactly the image you name, so your code, its runtime and its service manager have to be in that image already. ",[18,315,125],{}," passes ",[18,318,319],{},"image"," straight to LXD, so anything your cluster can resolve works:",[32,322,323,336],{},[35,324,325],{},[38,326,327,330,333],{},[41,328,329],{},"Image",[41,331,332],{},"Example",[41,334,335],{},"Good for",[48,337,338,355],{},[38,339,340,343,352],{},[53,341,342],{},"A public remote",[53,344,345,348,349],{},[18,346,347],{},"ubuntu:24.04",", ",[18,350,351],{},"images:debian\u002F12",[53,353,354],{},"Services, load balancers, smoke tests",[38,356,357,360,365],{},[53,358,359],{},"An image you published",[53,361,362],{},[18,363,364],{},"shop-web-7",[53,366,367],{},"Your own applications",[14,369,370],{},"The simplest way to make your own is to build it on the cluster and publish it. Images published on one member are available to all of them:",[152,372,376],{"className":373,"code":374,"language":375,"meta":158,"style":158},"language-bash shiki shiki-themes github-dark-high-contrast","ssh root@\u003Cany-member>\nlxc launch ubuntu:24.04 build-shop\nlxc exec build-shop -- cloud-init status --wait      # let first boot finish\nlxc file push -r .\u002Fdist build-shop\u002Fopt\u002Fshop\u002F          # your build output\nlxc exec build-shop -- sh -ec '\n  apt-get update -q\n  DEBIAN_FRONTEND=noninteractive apt-get install -y -q nodejs\n  cp \u002Fopt\u002Fshop\u002Fdist\u002Fshop.service \u002Fetc\u002Fsystemd\u002Fsystem\u002F\n  systemctl enable shop'\nlxc stop build-shop\nlxc publish build-shop --alias shop-web-7\nlxc delete build-shop\n","bash",[18,377,378,405,420,448,471,491,497,503,509,515,525,541],{"__ignoreMap":158},[379,380,383,387,391,395,398,402],"span",{"class":381,"line":382},"line",1,[379,384,386],{"class":385},"s_sBn","ssh",[379,388,390],{"class":389},"sTRMh"," root@",[379,392,394],{"class":393},"sWyjQ","\u003C",[379,396,397],{"class":389},"any-membe",[379,399,401],{"class":400},"sMAXC","r",[379,403,404],{"class":393},">\n",[379,406,408,411,414,417],{"class":381,"line":407},2,[379,409,410],{"class":385},"lxc",[379,412,413],{"class":389}," launch",[379,415,416],{"class":389}," ubuntu:24.04",[379,418,419],{"class":389}," build-shop\n",[379,421,423,425,428,431,435,438,441,444],{"class":381,"line":422},3,[379,424,410],{"class":385},[379,426,427],{"class":389}," exec",[379,429,430],{"class":389}," build-shop",[379,432,434],{"class":433},"sCcAr"," --",[379,436,437],{"class":389}," cloud-init",[379,439,440],{"class":389}," status",[379,442,443],{"class":433}," --wait",[379,445,447],{"class":446},"sQrFR","      # let first boot finish\n",[379,449,451,453,456,459,462,465,468],{"class":381,"line":450},4,[379,452,410],{"class":385},[379,454,455],{"class":389}," file",[379,457,458],{"class":389}," push",[379,460,461],{"class":433}," -r",[379,463,464],{"class":389}," .\u002Fdist",[379,466,467],{"class":389}," build-shop\u002Fopt\u002Fshop\u002F",[379,469,470],{"class":446},"          # your build output\n",[379,472,474,476,478,480,482,485,488],{"class":381,"line":473},5,[379,475,410],{"class":385},[379,477,427],{"class":389},[379,479,430],{"class":389},[379,481,434],{"class":433},[379,483,484],{"class":389}," sh",[379,486,487],{"class":433}," -ec",[379,489,490],{"class":389}," '\n",[379,492,494],{"class":381,"line":493},6,[379,495,496],{"class":389},"  apt-get update -q\n",[379,498,500],{"class":381,"line":499},7,[379,501,502],{"class":389},"  DEBIAN_FRONTEND=noninteractive apt-get install -y -q nodejs\n",[379,504,506],{"class":381,"line":505},8,[379,507,508],{"class":389},"  cp \u002Fopt\u002Fshop\u002Fdist\u002Fshop.service \u002Fetc\u002Fsystemd\u002Fsystem\u002F\n",[379,510,512],{"class":381,"line":511},9,[379,513,514],{"class":389},"  systemctl enable shop'\n",[379,516,518,520,523],{"class":381,"line":517},10,[379,519,410],{"class":385},[379,521,522],{"class":389}," stop",[379,524,419],{"class":389},[379,526,528,530,533,535,538],{"class":381,"line":527},11,[379,529,410],{"class":385},[379,531,532],{"class":389}," publish",[379,534,430],{"class":389},[379,536,537],{"class":433}," --alias",[379,539,540],{"class":389}," shop-web-7\n",[379,542,544,546,549],{"class":381,"line":543},12,[379,545,410],{"class":385},[379,547,548],{"class":389}," delete",[379,550,419],{"class":389},[552,553,555,574],"note",{"kind":554},"warning",[14,556,557,558,560,561,564,565,568,569,69],{},"An image is either a container image or a VM image. One published from a container can't boot in a ",[18,559,68],{}," group: LXD refuses with ",[18,562,563],{},"Asked for a VM but image is of type container",". Build VM images from a VM (",[18,566,567],{},"lxc launch … --vm","). See ",[570,571,573],"a",{"href":572},"\u002Fdocs\u002Fapplications\u002Fvms","Launch a VM",[14,575,576,577,579,580,583],{},"The reverse fails quietly. ",[18,578,125],{}," only passes ",[18,581,582],{},"--vm"," for VM groups, and LXD follows the image's own type otherwise, so a VM image in a container group comes up as a VM.",[14,585,586,587,348,590,593,594,600],{},"Give each build a new alias (",[18,588,589],{},"shop-web-8",[18,591,592],{},"shop-web-9",") and ship it with ",[570,595,597],{"href":596},"\u002Fdocs\u002Fapplications\u002Fday-two#upgrade-a-group",[18,598,599],{},"sg application upgrade --image",". Reusing an alias for different bytes makes rollback meaningless.",[552,602,604],{"kind":603},"tip",[14,605,606,607,109,610,21,612,614],{},"Service groups (PostgreSQL, ClickHouse) are the exception: use ",[18,608,609],{},"ubuntu:22.04",[18,611,347],{},[18,613,125],{}," installs and configures the database for you.",[27,616,618],{"id":617},"how-a-deploy-decides-it-worked","How a deploy decides it worked",[14,620,621],{},"A deploy isn't done when the instances start. It's done when:",[623,624,625,633,636],"ol",{},[626,627,628,629,632],"li",{},"every instance's ",[18,630,631],{},"health"," command succeeds inside it,",[626,634,635],{},"the load balancer (if any) is configured with the healthy backends, and",[626,637,638,639,69],{},"every exposed port and the load balancer's listener answer ",[56,640,641],{},"from your workstation",[14,643,644],{},"Only then is it recorded as a generation. That's why your workstation needs to be on the tailnet: exposed ports are published on each member's tailnet address.",[27,646,648],{"id":647},"where-to-next","Where to next",[650,651,652,659,664,671,678],"ul",{},[626,653,654,658],{},[570,655,657],{"href":656},"\u002Fdocs\u002Fapplications\u002Ffirst-application","Launch your first application",": two web containers behind HAProxy.",[626,660,661,663],{},[570,662,573],{"href":572},": the same, as virtual machines with their own disks.",[626,665,666,670],{},[570,667,669],{"href":668},"\u002Fdocs\u002Fapplications\u002Fdatabases","Add a database",": PostgreSQL or ClickHouse on a block volume.",[626,672,673,677],{},[570,674,676],{"href":675},"\u002Fdocs\u002Fapplications\u002Fexamples","Application examples",": complete specs to copy.",[626,679,680,684],{},[570,681,683],{"href":682},"\u002Fdocs\u002Freference\u002Fapplication-spec","application.yaml reference",": every field and rule.",[686,687,688],"style",{},"html pre.shiki code .s_sBn, html code.shiki .s_sBn{--shiki-default:#FFB757}html pre.shiki code .sTRMh, html code.shiki .sTRMh{--shiki-default:#ADDCFF}html pre.shiki code .sWyjQ, html code.shiki .sWyjQ{--shiki-default:#FF9492}html pre.shiki code .sMAXC, html code.shiki .sMAXC{--shiki-default:#F0F3F6}html pre.shiki code .sCcAr, html code.shiki .sCcAr{--shiki-default:#91CBFF}html pre.shiki code .sQrFR, html code.shiki .sQrFR{--shiki-default:#BDC4CC}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":158,"searchDepth":407,"depth":407,"links":690},[691,692,693,694,695],{"id":29,"depth":407,"text":30},{"id":149,"depth":407,"text":150},{"id":306,"depth":407,"text":307},{"id":617,"depth":407,"text":618},{"id":647,"depth":407,"text":648},"How sg application deploys groups of containers and VMs, services and a load balancer onto a cluster, and where your code comes from.","md",{},true,"\u002Fdocs\u002Fapplications",{"title":5,"description":696},"docs\u002Fapplications\u002Findex","VKeDb4Wq2eMiS0g7-AWWfiwrXIgoL-x4EHffvCpHcY0",1796464240883]